- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2023 05:33 AM
Hi All,
I am required to cancel some redundant flows in waiting stage in flow designer using a script but when i run the script in background I can see some records being deleted namely -
sys_json_chunk and
sys_flow_rw_action
Just wanted to confirm whether it will have an impact or not.
Code -
var flow = new GlideRecord("sys_flow_context");
flow.addQuery('name', 'yourflow'); // your flow name
flow.addQuery('source_record', 'sysId of record');
flow.addEncodedQuery('stateINWAITING');
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 for redundant request');
}
}
Thanks,
Vivek
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2023 06:20 AM
script looks fine to me.
Did you check the state got updated?
can you try this
var now_GR = new GlideRecord("sys_flow_context");
now_GR.addQuery("name", "NAME OF FLOW TO CANCEL HERE");
now_GR.addQuery('source_record', 'sysId of record');
now_GR.addEncodedQuery('stateINWAITING');
now_GR.query();
while (now_GR.next()) {
sn_fd.FlowAPI.cancel(now_GR.getUniqueValue(), 'Cancelling this flow for redundant request');
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2023 06:20 AM
script looks fine to me.
Did you check the state got updated?
can you try this
var now_GR = new GlideRecord("sys_flow_context");
now_GR.addQuery("name", "NAME OF FLOW TO CANCEL HERE");
now_GR.addQuery('source_record', 'sysId of record');
now_GR.addEncodedQuery('stateINWAITING');
now_GR.query();
while (now_GR.next()) {
sn_fd.FlowAPI.cancel(now_GR.getUniqueValue(), 'Cancelling this flow for redundant request');
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader