End flow and subflows associated with a record

CCZMAX1
Mega Sage

Hi does anyone know if there is a way to end a flow and any subflows  that is running against a record if the user cancels the record.  I have a few wait conditions etc. that will never run if the user cancels the record.

 

Many thanks

Max 

2 ACCEPTED SOLUTIONS

James Chun
Kilo Patron

Hi @CCZMAX1,

 

Have a look at the OOB Business Rule - cancel flow on request cancelled/deleted (sys_script.do?sys_id=062422410f2100108af26b198b767eb0)

 

Cheers

View solution in original post

Satishkumar B
Giga Sage
Giga Sage

Hi @CCZMAX1 

please check this:

https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0750702

-----------------------------------------------------------------------------------

Please consider marking my reply as Helpful  👍 and/or Accept Solution ✔️✔️ , if applicable. Thanks!



View solution in original post

3 REPLIES 3

James Chun
Kilo Patron

Hi @CCZMAX1,

 

Have a look at the OOB Business Rule - cancel flow on request cancelled/deleted (sys_script.do?sys_id=062422410f2100108af26b198b767eb0)

 

Cheers

Satishkumar B
Giga Sage
Giga Sage

Hi @CCZMAX1 

please check this:

https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0750702

-----------------------------------------------------------------------------------

Please consider marking my reply as Helpful  👍 and/or Accept Solution ✔️✔️ , if applicable. Thanks!



Hi @CCZMAX1 ,

 

Please try BR 

Add a script action to the Business Rule to check for cancellation and terminate any active flows.

 

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

// Check if the state has changed to 'Canceled'
if (current.state == 'Canceled' && current.state != previous.state) {

// Query active flows associated with the current record
var activeFlows = new GlideRecord('sys_flow_instance');
activeFlows.addQuery('table', current.getTableName()); // Adjust to your table name
activeFlows.addQuery('record_id', current.sys_id); // Adjust to your record's sys_id
activeFlows.addQuery('state', 'IN', 'started,running,pending');
activeFlows.query();

while (activeFlows.next()) {
// Terminate each active flow
var flowInstance = new FlowInstance();
flowInstance.terminate(activeFlows.sys_id);
}
}

})(current, previous);