ServiceNow Learning 47: Run a Flow/SubFlow from any server side script in ServiceNow.
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2023 01:46 AM - edited 10-16-2023 03:24 AM
Hi All,
I came to know very interesting topic to discuss today which how can call our flow at any condition or asyc by our any server side script.
Below code will us to call our subflow from any server-side scripting.
try {
var inputs = {};
inputs['visitor_data_record'] = current; // GlideRecord of table: x_snc_visitor_ma_1_visitor
// Execute Synchronously: Run in foreground. Code snippet has access to outputs.
var result = sn_fd.FlowAPI.getRunner().subflow('x_snc_visitor_ma_1.send_visitor_data_to_robot_queue').inForeground().withInputs(inputs).run();
var outputs = result.getOutputs();
// Current subflow has no outputs defined.
} catch (ex) {
var message = ex.getMessage();
gs.error(message);
}
This is something new. Although you have the trigger conditions in flow designer however in case you want to utilize the same subflow in our script also. You can use this method.
API Name : sn_fd.FlowAPI
I hope this article helpful. Please mark it as helpful and bookmark if you like it.
Note : I will cover all the other function this API supports in my future post.
Thanks,
Shamma
Regards,Shamma Negi
2 REPLIES 2

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2023 02:19 AM
@Shamma Negi Not only the flow but using sn_fd.FlowAPI you can also call the actions directly. Hope this helps.
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2023 03:22 AM
Yes I will cover all the function this API gives us in my future post.
Thanks for suggesting.
Regards,Shamma Negi