trigger a subflow from scripted rest api

Akshay Jugran
Tera Expert

Hi all,

I want to trigger a subflow from a scripted rest api so that i can get the output of that subflow stored in some variable.

If this is possible please guide me with this.

5 REPLIES 5

Mohith Devatte
Tera Sage
Tera Sage

Hello @Akshay Jugran ,

 

try doing this 

try {
var inputs = {};
inputs['input_name'] = ; //pass your input accordingly
 var result = sn_fd.FlowAPI.getRunner().subflow('subflow_name').inForeground().withInputs(inputs).run();
var outputs = result.getOutputs();
} catch (ex) {
var message = ex.getMessage();
gs.error(message);
}
 
})();

You need to run this script by passing your inputs accordingly and result will be stored in "outputs" variable 

 

Hope this helps 

Mark the answer correct if this helps you 

Thanks

In this case, where I want to call the flow from the script, what should I set as trigger while creating the flow in servicenow?

 

Thanks,

this solution works to me.

Abhijeet_Pawar
Tera Guru

Hello @Akshay Jugran,

You can call a sub flow using the "Copy Code Snippet" functionality of Flow. Please find the image below, which will guide you on how to create a code snippet.

Hope this helps!

Please mark this answer as correct if it assists you.

Thank you!