need fix script for cancel and restart current running flow context
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-08-2024 05:27 AM
Hi All,
we need a fix script for cancel and restart the current running flow contexts , please help me.
#flow context #flow designer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-08-2024 05:32 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-08-2024 06:28 AM
I have used below script, it cancel the flows, but didn't start the flows
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-08-2024 01:08 PM
Hi @siva14 ,
Untested code but you can try,
try {
var inputs = {};
inputs['table_name'] = 'sc_req_item';
inputs['request_item'] = current;
// Start Asynchronously: Uncomment to run in background.
sn_fd.FlowAPI.getRunner().flow('global.test').inBackground().withInputs(inputs).run();
// Execute Synchronously: Run in foreground.
//sn_fd.FlowAPI.getRunner().flow('global.test').inForeground().withInputs(inputs).run();
} catch (ex) {
var message = ex.getMessage();
gs.error(message);
}
Please mark this comment as Correct Answer/Helpful if it helped you.
Regards,
Swathi Sarang
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-08-2024 04:20 PM
Hi @siva14 ,
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');
}
}
}
})();
If I could help you with your Query then, please hit the Thumb Icon and mark it as Correct !!
Thanks & Regards,
Sumanth Meda
