How can I cancel a Flow Designer Flow instance if Business Rule is Triggered?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-06-2019 03:04 PM
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?
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-16-2019 08:16 PM
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!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-16-2020 12:51 AM
Hi,
were you able to mange that. Can you share your solution on that.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-09-2020 12:07 PM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-10-2021 07:13 AM
https://community.servicenow.com/community?id=community_article&sys_id=ef133788db3af780190dfb2439961959