Write a fix script to stop/cancel a flow context
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-26-2022 09:40 PM
FIX SCRIPT
3 REPLIES 3
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-26-2022 09:44 PM
Hi,
example below
Give your table name, record sysID etc and flow name
(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'); // your 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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2022 09:46 PM
Hope you are doing good.
Did my reply answer your question?
If my response helped please close the thread by marking appropriate response as correct so that it benefits future readers.
Regards
Ankur
Regards,
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-09-2023 10:36 PM
// Get the flow context for your record
var flowContextGR = new GlideRecord("sys_flow_context");
flowContextGR .addQuery('source_record', 'sys_id'); //sys_id of the record for which the flow needs be cancelled
flowContextGR .query();
if(flowContextGR .next()){
//cancel the flow
sn_fd.FlowAPI.cancel(flowContextGR .sys_id, gs.getMessage('manually by {0}', gs.getSession().getUserName()));
}
