- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2023 12:57 AM
Hello All,
I created a after BR to cancel flow_context of the current ritm, the ritm is cancelling but upon checking the flow context record, it is completed instead of cancelled.
Can anyone check my BR?:
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2023 01:54 AM
@Al-jhon Please create a BR on sc_req_item table and add below code to it
ServiceNow Community Rising Star, Class of 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2023 02:06 AM
try this once
var flow = new GlideRecord("sys_flow_context");
flow.addQuery('source_record', current.getUniqueValue());
flow.addEncodedQuery('stateINWAITING,IN_PROGRESS,QUEUED');
flow.query();
if(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 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
05-31-2023 02:03 AM
Please check the flow API documentation.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2023 02:06 AM
try this once
var flow = new GlideRecord("sys_flow_context");
flow.addQuery('source_record', current.getUniqueValue());
flow.addEncodedQuery('stateINWAITING,IN_PROGRESS,QUEUED');
flow.query();
if(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 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
05-31-2023 04:20 PM
Hello @Ankur Bawiskar and @jaheerhattiwale , thanks for sharing the ideas.
I found out that the BR that i created long time ago was corrupted after the patch upgrade to UTAH.
I just created a new BR with the same script and just inactive the old one.
(function executeRule(current, previous /*null when async*/) {
//If request has a flow desinger execution associated with it, cancel it.
if ((current.stage == 'Request Cancelled') && current.flow_context && !current.flow_context.nil()){
new sn_fd.FlowAPI.cancel(current.flow_context, "by user " + gs.getSession().getUserName());
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2023 04:54 PM
@Al-jhon Thats good. But this is exactly the same solution what I proposed. So can you please mark my answer also as correct answer so that it helps the others.
Thanks and regards,
Jaheer
ServiceNow Community Rising Star, Class of 2023