Call sub flow from workflow run script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2025 01:11 AM
I am invoking a sub flow synchronously from workflow run script activity, however it is not waiting at the run script activity till the sub flow completes and it going to the next steps. Is there a way to stop the run script activity till the sub flow completes?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2025 01:14 AM
since you are calling the subflow via script and it's synchronous call using inForeground() method it should wait
share your script here and some screenshots.
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2025 01:21 AM
Please check the below code
try {
var inputs = {};
inputs['incident'] = current; // GlideRecord of table: task
// Start Asynchronously: Uncomment to run in background. Code snippet will not have access to outputs.
// sn_fd.FlowAPI.getRunner().subflow('global.create_problem_from_incident_using_workflow_script').inBackground().withInputs(inputs).run();
// Execute Synchronously: Run in foreground. Code snippet has access to outputs.
var result = sn_fd.FlowAPI.getRunner().subflow('global.create_problem_from_incident_using_workflow_script').inForeground().withInputs(inputs).run();
var outputs = result.getOutputs();
// Get Outputs:
// Note: outputs can only be retrieved when executing synchronously.
var incident_task = outputs['incident_task']; // Reference
} catch (ex) {
var message = ex.getMessage();
gs.error("error in workflow Script for subflow " + message);
}
And also find the screenshots of workflow context and sub flow context
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2025 01:57 AM
not a good idea to make workflow run script wait based on flow outcome
Why not move that logic to workflow wait itself?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader