
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2020 08:35 AM
Hi, I'm triggering my flow through the script in my server-side UI action "Request banking data" from the "Claim's" form.
try {
var inputs = {};
inputs['current'] = current;
inputs['table_name'] = 'u_club_claim';
sn_fd.FlowAPI.startFlow('decision_logic_request', inputs);
} catch (ex) {
var message = ex.getMessage();
gs.error(message);
}
Then I will need to cancel this flow, I successfuly can do it with following script that I found
var flowContextGr = new GlideRecord('sys_flow_context');
flowContextGr.addQuery('source_record', 'e9729d21dbb09c105f65ba03e29619fd'); // NEED REPLACE THIS!!!
flowContextGr.addEncodedQuery('state=WAITING^ORstate=IN_PROGRESS^ORstate=QUEUED');
flowContextGr.query();
while(flowContextGr.next()){
var gpa = new sn_ph.GlideProcessAutomation(flowContextGr.getUniqueValue());
gpa.cancel('Cancelled from button "Request banking data"');
}
BUT! I can't properly query it, because source_record(document id type) field, is populated not by my record (like in triggering by condition), but with sys_id of my UI action, so I can't find in sys_flow_context my context by sys_id of my record.
This is how reference looks like:
Is there a way how I can set this source_record field manually from snippet, or maybe can I query my flow context through some other tables?
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2020 08:54 AM
.startFlow returns you contextid and that contextID can be used to cancel the flow. Update below line in your script to store the contextID in a variable.
var contextId = sn_fd.FlowAPI.startFlow('decision_logic_request', inputs);
Use below line to cancel the flow.
sn_fd.FlowAPI.cancel(contextId, 'Flow took too long to execute.'); // Call the cancel() method using the context Id returned from the startFlow() method
Please mark this accepted & helpful if it answered your question. Thanks!
Muhammad

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2020 08:54 AM
.startFlow returns you contextid and that contextID can be used to cancel the flow. Update below line in your script to store the contextID in a variable.
var contextId = sn_fd.FlowAPI.startFlow('decision_logic_request', inputs);
Use below line to cancel the flow.
sn_fd.FlowAPI.cancel(contextId, 'Flow took too long to execute.'); // Call the cancel() method using the context Id returned from the startFlow() method
Please mark this accepted & helpful if it answered your question. Thanks!
Muhammad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2020 10:32 AM
Unfortunately, we are using New York and the .cancel method is not available in scope 😕
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2020 10:32 AM
Using that method would only work in Orlando.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2020 12:00 PM
1 record (Claim) in my case could have multiple flow executions (4-5), if I will use
var contextId = sn_fd.FlowAPI.startFlow('decision_logic_request', inputs);
I would have to store all this contexId's in some comma-separated field, before cancel all of them at once (when I will need it), like workaround it's fine, but still would have ability to query all of them through sys_flow_context by sys_id of my Claim (record, where flows was triggered of)