Business Rule to cancel or end the Flow Designer Flow

ShivangiC
Tera Contributor

Requirement:- If any of the tasks is marked as Closed Incomplete, RITM is marked as Closed Incomplete and the flow associated with the Catalog item must be ended.

 

I have designed a Business Rule for it but its not working , Please help !!

(function executeRule(current, previous /*null when async*/) {

    var ritm = new GlideRecord('sc_req_item');
        if (ritm.get(current.request_item)) {
            // Check if the RITM is not already closed incomplete
            if (ritm.state != 4) {
                ritm.state = 4;
                ritm.update();
               
                // Optionally, you can add logic to terminate the Flow Designer flow
                // Example of handling Flow Designer flow termination
                var flow = new GlideRecord('sys_flow_context');
                var fc = new GlideFlow();
                gs.addInfoMessage('document_id is: '+ritm.sys_id);
                flow.query();
                if(flow.get( ritm.sys_id)) {
                    fc.cancel(flow.sys_id);
                    gs.addErrorMessage('Flow context with SYS ID :'+flow.sys_id+' is ended');
                }
            }
        }

})(current, previous);

 

1 ACCEPTED SOLUTION

Zach Koch
Giga Sage
Giga Sage

This knowledge article may help you, as it shows how to cancel a flow in progress.

KB0959612 

 

If this information helped resolve your issue, please remember to mark response correct and thumbs up to help future community members on this information, thanks!

View solution in original post

3 REPLIES 3

Zach Koch
Giga Sage
Giga Sage

This knowledge article may help you, as it shows how to cancel a flow in progress.

KB0959612 

 

If this information helped resolve your issue, please remember to mark response correct and thumbs up to help future community members on this information, thanks!

kdelbridge
Tera Expert

Hello @ShivangiC , were you able to get this resolved? I have a similar issue trying to solve.

Yes, the following KB article helped me resolve it :-

How to Cancel In Progress Flow Executions - Support and Troubleshooting