Cancel a subflow

Servicenow Use4
Kilo Guru

Hello experts,

 

I have a flow which calls multiple subflows based on conditions. Essentially, there are nested subflows, each creating HR Tasks, triggering notifications etc. 

 

Here is what is problem is: If I mark the HR Case as Cancelled, the OOTB functionality sets the HR Task as Closed Incomplete. Now, that particular subflow state (from where this HR Task is created) is still showing as 'Complete' and subsequent part of the main flow or the subflow from where this was called gets executed and other tasks get created. I do not want this to happen. If the HR Case itself is Cancelled, nothing else should get created.

How do I prevent the remaining flow from execution?

 

Any leads are appreciated.

 

Thanks!

1 ACCEPTED SOLUTION

Mark Manders
Mega Patron

Any action that is done, should be checking on the case state. So if somewhere in the flow you are calling a next subflow (or within a subflow actions are performed), you need a check on the state of the Case.

I don't know how complicated the flow is, but it could be as easy as just put a look up record to check on the case state and an 'end flow' if it is canceled.


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

View solution in original post

6 REPLIES 6

Hi @Mark Manders Thanks for responding to my question. I had to do something similar to what you suggested. I had to check if the case is cancelled or not at critical points in my overall flow. If yes, then 'End subflow'.
It worked. Thanks!

Tai Vu
Kilo Patron
Kilo Patron

Hi @Servicenow Use4 

Have you tried to cancel the flow when the HR Case get cancelled?

Cancels a paused or running flow, subflow, or action.

cancel(String contextId, String reason)

var now_GR = new GlideRecord("sys_flow_context");
now_GR.addQuery("name", "Test Flow");
now_GR.query();
while (now_GR.next()) {
   sn_fd.FlowAPI.cancel(now_GR.getUniqueValue(), 'Canceling Test Flows');
}

 

Cheers,

Tai Vu