Flows are not canceled after ticket closed

Thiagofmeira
Kilo Guru

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

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@Thiagofmeira 

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.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

@Thiagofmeira 

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.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

@Thiagofmeira 

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.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

@Thiagofmeira 

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.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader