How can I cancel a Flow Designer Flow instance if Business Rule is Triggered?

Jordan Humphre1
Giga Contributor

So I have a flow currently that monitors inactivity on an incident record. If the status is "Waiting User" then a new flow instance execution kicks off for a flow called "Inactivity - Waiting User".

If the user responds to the incident before the flow reaches its final stage, the incident status changes to "In Progress" and the remaining steps of the flow would not meet the conditions to continue.

My question is, if the user responds back during the incident and the status updates to "In Progress" I want to cancel any running flows for the Inactivity - Waiting User on this particular  incident.

Do you treat workflows and flows the same programatically?

4 REPLIES 4

Andrew Albury-D
Mega Guru

Morning! I've been digging in to this and I think I have it. 

The only place in the platform I've found that links a flow context to the record (and shows you all the details about that flow) is in the Event Queue! There's an event called "flow.start" which includes a massive JSON string in it's param2 that includes links to the records that generated it (Inputs, I'm assuming, if you have created a flow/subflow like I have for a similar use case) and a reference to the context.

You will need to step through the Events against the table you are working on (for me "sys_flow_subflow_plan") looking for contexts where param2 contains the record that you are referencing, then use the plan_context_id > display_value from the JSON to work out if the context relating to that record is "waiting", then set it's status to "cancelled".

I'm going to try do this myself, and maybe write an article about how I accomplished it, but it's definately feeling like a script include to me.

happy days!

Hi,

were you able to mange that. Can you share your solution on that. 

jxsaxton421
Tera Guru

According to the folks in the SNDevs slack, you should use the api to cancel a flow. It looks like as of New York, there is only a Global .cancel method available. Orlando has the .cancel in scope to use. 

Do not mess with the sys_flow_context table, that's a system table that should not be messed with. 

https://developer.servicenow.com/dev.do#!/reference/api/newyork/server/sn_fd-namespace/ScriptableFlo...

 

hammad ul aziz2
Mega Guru

https://community.servicenow.com/community?id=community_article&sys_id=ef133788db3af780190dfb2439961959