- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2022 08:29 AM
I have a business rule on a table that runs what we can Service Requests. The rule is working, but it's canceling all of the running flows (Not the desired results). I want it only to cancel the context of the changed record.
The business rule is setup as follows:
Active: True
Advanced: True
Table: Service Request
When to Run Section: async
Update: True
Filter Condition: State changes from "Waiting-Client"
Nothing on the Actions tab:
Advanced Tab has the following code:
(function executeRule(current, previous /*null when async*/) {
var gr = new GlideRecord("sys_flow_context");
gr.addQuery("name","SR eLearning/Threat emulation Nudge");
gr.query();
while (gr.next()){
sn_fd.FlowAPI.cancel(gr.getUniqueValue(), 'Canceling Nudge due to state change');
}
})(current, previous);
How can I stop just the flow that is connected to the specific Service Request and not all of them?
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2022 08:42 AM
Hey
You can cancel an individual flow context by modifying your code as below. The example below is me trying to cancel a Flow for a Request I have made.
var grRequest = new GlideRecord('sc_req_item');
// Enter the sys_id of your current record here, current.getValue('sys_id');
if (grRequest.get('6b6bc3a5970111102d2a38271153afe8')) {
var flowContext = new GlideRecord("sys_flow_context");
flowContext.addQuery('name', 'Service Catalog Item Request'); // flow name
flowContext.addQuery('source_record', grRequest.getValue('sys_id'));
flowContext.addEncodedQuery('stateINWAITING,IN_PROGRESS,QUEUED');
flowContext.query();
flowContext.setLimit(1);
while (flowContext.next()) {
var gpa = new sn_ph.GlideProcessAutomation(flowContext.getValue('sys_id'));
if (!gpa.isTerminated()) {
gpa.cancel('Flow has been cancelled');
}
}
}
Thanks
Please mark this answer as correct or helpful if it solved your issue, thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2022 08:42 AM
Hey
You can cancel an individual flow context by modifying your code as below. The example below is me trying to cancel a Flow for a Request I have made.
var grRequest = new GlideRecord('sc_req_item');
// Enter the sys_id of your current record here, current.getValue('sys_id');
if (grRequest.get('6b6bc3a5970111102d2a38271153afe8')) {
var flowContext = new GlideRecord("sys_flow_context");
flowContext.addQuery('name', 'Service Catalog Item Request'); // flow name
flowContext.addQuery('source_record', grRequest.getValue('sys_id'));
flowContext.addEncodedQuery('stateINWAITING,IN_PROGRESS,QUEUED');
flowContext.query();
flowContext.setLimit(1);
while (flowContext.next()) {
var gpa = new sn_ph.GlideProcessAutomation(flowContext.getValue('sys_id'));
if (!gpa.isTerminated()) {
gpa.cancel('Flow has been cancelled');
}
}
}
Thanks
Please mark this answer as correct or helpful if it solved your issue, thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2022 09:16 AM