How to Cancel the Existing Execution in the Sub Flow to keep only one Active Execution.

Imran4
Tera Contributor

Hi Community! I am having a concern in cancelling the existing flow executions to keep only one execution run for the same record. My requirement is, In CSM, I need to call the Sub flow from the After BR when a field changes in the Account Record. I am passing Account data as inputs to the Sub flow. So whenever the sub flow triggers, it should check if there are any flow contexts are running to cancel them and keep the existing flow execution. I am giving conditions as below:

Action: Look Up Records

Table: sys_flow_context

Under the conditions,

Name: [MY_FLOW_NAME],

state: Waiting,

Source Table: sys_script

Source Record: [BR_SYS_ID]

Created By: [INPUTS_logged_In_user]

By this I am able to cancel the Flow executions which are created by the logged in user. But If any other user created for the same account, I am not able to cancel them so that I can keep only one execution in the wait condition. Else if I remove the Created By condition, it is cancelling all the flow executions created by Script. Or If I keep the created by condition, it is cancelling all the flow executions created by the user no matter for which account it is? So I want to add condition based on Account so that I can filter if there are any ongoing executions to cancel them and can keep the latest execution in waiting state. Can you please help me how to add the Account condition or filter to the sys_flow_context table/or to my existing conditions? Thank you.

 

2 REPLIES 2

pr8172510
Kilo Sage

Hi @Imran4,

 sys_flow_context does not store your Account record directly in a way that can be reliably filtered using standard conditions.

Instead of filtering by Created By, use a unique identifier for the Account (for example, the Account Sys ID) and pass it into the flow as an input.

Then store/query that value when looking for existing executions.


Flow Name = My Subflow State IN Waiting, In Progress Source Record = Account Sys ID

 

This ensures you only cancel executions related to the same Account, regardless of which user triggered them.

If you're triggering from an Account Business Rule, consider passing current.sys_id

 

to the Subflow and use that value to identify and cancel older executions before continuing with the latest one.

Imran4
Tera Contributor

Hi @pr8172510 , 

Thanks for the response!

Tried with passing the mentioned values, there is no unique way to capture Account Sys ID. If I pass Account Sys ID in the Source Record, then I am failing to cancel the flow executions. Sorry, this is not working.