Trigger Flow from script with inputs

Felipe cardona
Kilo Contributor

Hello Guys, we are migrating a workflow to a flow designer, and we want to do it a little different, before we used to trigger the workflow everyday at a certain time, checked every possible car to see IF it's going to be available tomorrow or not, and change the status of unavailable to available. Now we need to trigger the new flow via a script, this script will trigger the flow everytime an car has a change in status to available, and the availability is "tomorrow". How can we do that? how can i:
trigger a flow from a script?
send this flow the variables of the newly available car? (like, color, model, blablabla)

 

thanks in advance

3 REPLIES 3

Brian Bouchard
Mega Sage

Couple of clarifying questions:

 

Does it need to be triggered from the script, or can you simply define a record trigger when the record is Created Or Updated and then set the condition of the trigger to "status changes" and "availability = tomorrow"?

 

Also, is "tomorrow" a value, or is availability a date or datetime field and you need to calculate what tomorrow is?

It needs to be triggered from a script, it needs to check everyday to see if there´s a status change in the availability, a script that checks the records everyday and see if one of the cars changed the status, also, tomorrow is the date when the car is going to be available, like in stock. the system has let´s say a bmw m3 registered in the system since december, like we have the car, but we don´t, when the car is registered in the system it just stays there, but we register it with a date when we are going to actually have it on stock, so the car has a field "status" (boolean, available true or false) and it will change on the specified date, let's say, on may 11th it will check every car, and the cars that are going to be available on stock on may 12th change status from unavailable to available

Christopher096
Tera Guru
Tera Guru

Hi Felipe,

You can use Business rule to trigger your respective Flow based on your requirement. In the Business rule you can define the condition and all

To trigger the Flow using Server Script, you can use either one of this:

1. executeFlow(String name, Map inputs, Number timeout) - Flows run using this method run synchronously.

e.g:  sn_fd.FlowAPI.executeFlow('global.test_flow', inputs, timeout) - Here the name is the scope and name of the flow to be executed,
for example global.flow_name

(function() {
try {
var inputs = {};
inputs['current'] = ; // GlideRecord of table:
inputs['table_name'] = 'incident';

// Execute Synchronously: Run in foreground.
// var timeout = ; //timeout in ms
//sn_fd.FlowAPI.executeFlow('global.test_flow', inputs, timeout)
sn_fd.FlowAPI.executeFlow('global.test_flow', inputs);
} catch (ex) {
var message = ex.getMessage();
gs.error(message);
}
})();

2. startFlow(String name, Map inputs) - Flows executed with this method run asynchronously.

e.g. :
(function() {

var now_GR = new GlideRecord('incident');
now_GR.addQuery('number', 'INC0009009');
now_GR.query();
now_GR.next();

try {
var inputs = {};
inputs['current'] = now_GR; // GlideRecord of table: Incident
inputs['table_name'] = 'incident';

var contextId = sn_fd.FlowAPI.startFlow('global.test_flow', inputs);

} catch (ex) {
var message = ex.getMessage();
gs.error(message);
}
})();

 

Hope my answer will be helpful for you.

 

Thanks

Christopher P