
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2025 05:40 AM
Hi everyone,
We have many flows in the HR scope and the tasks are triggered in sequence. It means that only after a task be closed, the next one is created.
The problem we are facing is that when the ticket is Closed/Canceled before the flow over, the flow continue to be executed and create new tasks even with the case closed.
Shouldn't the flows be cancelled when the task is closed or canceled?
Best regards,
Thiago
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2025 06:18 AM
are you handling this in flow?
If not then flow will continue doing what it's supposed to do irrespective of the state.
Add in your flow the logic to check if Case is open before creating the Tasks
OR
You can use this script to cancel the flow context using after update Business rule when Case is closed
var flow = new GlideRecord("sys_flow_context");
flow.addQuery('name', 'myFlow'); // flow name
flow.addQuery('source_record', current.getUniqueValue());
flow.addEncodedQuery('stateINWAITING,IN_PROGRESS,QUEUED');
flow.query();
if (flow.next()) {
var gpa = new sn_ph.GlideProcessAutomation(flow.getValue('sys_id'));
if (!gpa.isTerminated()) {
//cancel the flow and provide the reason
gpa.cancel('Cancelling this flow');
}
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2025 06:18 AM
are you handling this in flow?
If not then flow will continue doing what it's supposed to do irrespective of the state.
Add in your flow the logic to check if Case is open before creating the Tasks
OR
You can use this script to cancel the flow context using after update Business rule when Case is closed
var flow = new GlideRecord("sys_flow_context");
flow.addQuery('name', 'myFlow'); // flow name
flow.addQuery('source_record', current.getUniqueValue());
flow.addEncodedQuery('stateINWAITING,IN_PROGRESS,QUEUED');
flow.query();
if (flow.next()) {
var gpa = new sn_ph.GlideProcessAutomation(flow.getValue('sys_id'));
if (!gpa.isTerminated()) {
//cancel the flow and provide the reason
gpa.cancel('Cancelling this flow');
}
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2025 06:44 AM
Thank you for marking my response as helpful.
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2025 10:54 PM
Hope you are doing good.
Did my reply answer your question?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader