Flow designer: Filter the desired context in sys_flow_context in order to cancel it

Ihor
Giga Expert

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:
find_real_file.png

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?

1 ACCEPTED SOLUTION

MrMuhammad
Giga Sage

.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! 

Regards,
Muhammad

View solution in original post

6 REPLIES 6

Correct. You can push contextid's in an Array and query sys_flow_context, pass the array of context ids to get and cancel contexts. 

 

Please mark this accepted & helpful if it answered your question. Thanks! 

Regards,
Muhammad

Hi Igor, It would be great if you comeback and mark my response as ACCEPTED if your question has been answered. So that this thread can be closed and others looking for the same solution can see this on the top of their searches. Thanks!
Regards,
Muhammad