Cancel All Running Flows with One Click in Power App
January 25, 2025
The Problem
Have you ever had a runaway flow? I know I have.
Back in the early days, I would occasionally make a mistake resulting in an infinite loop, or a child flow being triggered a ridiculous amount of times.*
*Okay, TBH I occasionally still do this when I’m horsing around in my development environment
Sometimes the actions in the runaway flow start hitting throttle limits and they slow down, resulting in many flows stuck in a running status. This can impact the performance of your entire ecosystem and be very bad.
Canceling all the runs used to be a tedious processing of selecting them in batches of 20, or saving a copy of the runaway flow and then deleting it.
The Solution
Fortunately, Microsoft has added a “Cancel all flow runs” button.
This is great. Even better, there is an API endpoint you can use to cancel all flow runs for a selected flow. You can even find the link when you list your “workflows” (Processes) table in Dataverse:
Here is the endpoint:
https://<your_domain>.crm.dynamics.com/api/data/v9.1/workflows(<flow_name>)/Microsoft.Dynamics.CRM.CancelAllCloudFlowRuns
All you need to do is send an authorized POST to the url, and you will trigger the immediate cancellation of all running flows for the flow named in the url. You can do this in Power Automate or Power Apps with an Invoke an HTTP Request with Entra ID (preauthorized).
Example – Canvas App
Here’s how it works in a Power Apps Canvas App.
I have a Canvas App I’m building to manage Power Automate Cloud Flows in any environment. It uses the Dataverse “workflows” (Processes) table to list all flows in the environment, as well as HTTP calls to list all flow runs. In the screenshot below, I have opened up a flow called “Delay Flow Test” to view all the recent runs that belong to it.
The HTTP with Microsoft Entra ID (preauthorized) Invoke HTTP Action
I have added a “Cancel all flow runs” icon:
In its simplest version, the expression for “OnSelect” is as simple as this:
'HTTPwithMicrosoftEntraID(preauthorized)'.InvokeHttp("POST",$"/api/data/v9.1/workflows({loc_sel_flow.Process})/Microsoft.Dynamics.CRM.CancelAllCloudFlowRuns")
I’ve updated it to only run if there are running flows, and to send a notification. I’ve also moved the code to a confirmation popup to make sure the user wants to cancel all running flows.
In the end, this is what my code looked like:
This gets a count of the running flows that will be canceled, and performs a refresh of the select flow’s run history so that we can get immediate confirmation that the API action worked.
Make Sure Your “HTTP with Microsoft EntraID” connector is set up with a connection to your Dynamics Url, i.e. (https://<your_domain>.crm.dynamics.com)
Click Confirm to Invoke the HTTP and refresh flow runs
I click Confirm and receive this notification:
Flow history is immediately refreshed:
The flows that were submitted to the bulk cancellation API now show a “Cancelling” status.
Hope this helps!
If you found this post helpful please give it a like.
Power Platform Developer | WordPress | LinkedIn | YouTube: Mark’s Power Stuff | Buy me a coffee
Top comments (0)