ServiceNow Learning 66: Execute a Flow via Server-Side Script in ServiceNow

Shamma Negi
Kilo Sage
Kilo Sage

Hi All,

 

I have found a very interesting script wherein we have so many Flows API Method. Today, I would be covering the execute flow from scripts.

 

The FlowAPI object includes methods to run flows, subflows, and actions synchronously and asynchronously. Access FlowAPI methods in global and scoped scripts using the sn_fd.FlowAPI object.

Server-side scripts that use a synchronous method wait for the flow, subflow, or action to complete before proceeding. Scripts using a synchronous method can access subflow and action output variables. Flows do not have output variables. Methods that execute a flow, subflow, or action synchronously:

  • executeFlow(flow name, inputs)

 

Execute Gobal Application Flows:

 

For example, this script creates an inputs object and executes a global flow called test_flow.

// Map inputs. For a flow with a record trigger, inputs are the record and table
  var inputs = {};
  inputs['current'] = current; // GlideRecord of table:  
  inputs['table_name'] = 'incident';

   // Execute the global flow called test_flow 
   sn_fd.FlowAPI.executeFlow('global.test_flow', inputs);

An optional third parameter can be used with all these methods to set the timeout for the execution in milliseconds. If no value is specified, the timeout defaults to the value in the com.glide.hub.flow_api.default_execution_time property.

 

Execute Scoped Flows

 

For example, this script creates an inputs object and executes a scoped flow called scoped_test_flow.

// Map inputs. For a flow with a record trigger, inputs are the record and table
  var inputs = {};
  inputs['current'] = current; // GlideRecord of table:  
  inputs['table_name'] = 'x_financial_data';

   // Execute the scoped flow called test_flow 
   sn_fd.FlowAPI.executeFlow('<app-scope-name>.scoped_test_flow', inputs);

Hope this helps.

 

I hope this article helpful. Please mark it as helpful and bookmark if you like it.

 

Regards,

Shamma

Regards,Shamma Negi
0 REPLIES 0