Cancel running Flow contexts

harun_isakovic
Mega Guru

Hello Community,

I want to cancel running Flow contexts with a certain query. These flow contexts are related to many different RITMs so it's not just contexts for 1 RITM, but for like 1000 RITM.

Encoded query would be "state=WAITING^sys_created_bySTARTSWITHabde^name=FlowName"

Could someone assist with this?

 

1 ACCEPTED SOLUTION

Hi,

sample script below

(function() { 

var now_GR = new GlideRecord('incident'); 
now_GR.addQuery('number', 'INC0000050'); 
now_GR.query(); 
if(now_GR.next()){

// get the flow context for this INC

var flow = new GlideRecord("sys_flow_context");
flow.addQuery('name', 'myFlow'); // flow name
flow.addQuery('source_record', now_GR.getUniqueValue());
flow.addEncodedQuery('stateINWAITING,IN_PROGRESS,QUEUED');
flow.query();
while(flow.next()){

var gpa = new sn_ph.GlideProcessAutomation(flow.getValue('sys_id'));

if (!gpa.isTerminated()) {
//cancel the flow and provide the reason
gpa.cancel('Cancelling this flow');
}

}

}

})();

Regards
Ankur

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

View solution in original post

5 REPLIES 5

@harun.isakovic 

Hope you are doing good.

Did my reply answer your question?

If so, please mark appropriate response as correct & helpful so that the question will appear as resolved for others who may have a similar question in the future.

If not, please let us know if you need some more assistance.

Thanks!
Ankur

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