Cancel Ongoing Flow Runs in Microsoft Dynamics 365 Dataverse: Complete Guide
We came across an issue that a lot of flow runs that were accidentally triggered based upon a mutation of a Dataverse/CRM entity action in a specific flow.
Microsoft does have a solution to cancel runs using the power automate template (Power automation cancel bulk template)
However, the issue is that this cancel around 5000 flow runs in 18 hours since there is a delay of around 10 seconds. If you remove the delay, the flow does not give the expected results.
Authorization
Now the question is how to fix this issue?
There is a flow api that allows you to cancel flow runs, but there are some steps to take to be able to do this.
Create an app registration in microsoft azure ad/entra with the permission 'Flows.Manage.All' and add the redirect url 'https://global.consent.azure-apim.net/redirect' under Authentication
Add a secret to the app registration write this down because you won't be able to see it anymore after creation.
Acquire all flow runs for specific flow that have the status running
Method = Get
https://api.flow.microsoft.com/providers/Microsoft.ProcessSimple/environments/{Flow-Environment-Guid/flows/{Flow-Guid-Id}/runs?api-version=2016-11-01&$filter=Status
eq 'running'
https://api.flow.microsoft.com/providers/Microsoft.ProcessSimple/environments/{Flow-Environment-Guid}/flows/{Flow-Guid-Id}/runs/{Run Id}/cancel?api-version=2016-11-01
Comments
Post a Comment