Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to kill flow using script and trigger it using script

Alon Grod
Tera Expert

Hi,

 

im calling a client script that calls a script include and pass as a parameter a sys_id of a change_request.

How can I kill the current flow (not workflow) on the change_request and then trigger a new flow using his sys_id using using on the change_request

7 REPLIES 7

@Alon Grod 

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

PrashantT
Giga Guru

Hi @Alon Grod , 

You can achieve your requirement by following the below step.

 

var flow_GR = new GlideRecord("sys_flow_context"); 
flow_GR.addQuery("name", "flow name to cancel"); 
flow_GR.addQuery('source_record', 'sysid of the record');
flow_GR.addEncodedQuery('stateINWAITING'); // add the condition based on your flow stage
flow_GR.query(); 
while (flow_GR.next()) { 
sn_fd.FlowAPI.cancel(flow_GR.getUniqueValue(), 'Cancel this flow'); 

 

var flowAPI = new sn_fd.FlowAPI();

var inputs = { sys_id: 'your_parameter_sys_id_here' };

flowAPI.startSubflow('subflow_sys_id_name', inputs);

 

In this example I'm only providing a sys_id as input and expecting the subflow to contain a input "sysid".

 

Please accept my solution and give it a thumbs up if it's helpful for you.

 

Thanks & Regards,
Prashant

Hi @Alon Grod ,

Did you get the chance to check my code?

 

Please accept my solution and give it a thumbs up if it's helpful for you.

 

Thanks & Regards,
Prashant