Call sub flow from workflow run script

Girish12
Kilo Sage

Hi @Ankur Bawiskar 

 

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?

3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

@Girish12 

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.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Ankur Bawiskar 

 

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

Girish12_0-1747642859759.png

 

Girish12_1-1747642881593.png

 

@Girish12 

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.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader