How to cancel all pending approvals in Power Automate flow

Hello everyone and welcome to my blog. In today’s blog I shall discuss on how you can cancel pending approvals in Power Automate flow.

If you have been working on Power Automate for sometime now, you must have used the Approvals in Power Automate flow. However when using approvals, lot of time you will end up with approvals which are no longer valid and in pending state.

What if you need to cancel all these pending flow instances? Let’s see how we can accomplish this requirement.

Quite unknown to many, Approval flows instances are stored as records in DataVerse. Look for the table Approval (msdyn_flow_approval) in your DataVerse environment.

And this table contains all the information related to approval flow instance . Below is the screenshot of an approval record in Pending state,

The columns to look for here are Status, Status Reason and Result. These are the three important fields we need to update to cancel all pending flows. I will use an instant flow for this purpose.

I use the Manual trigger. The next job is to retrieve all instances of approvals which has Status = Active and Status Reason = Pending. I will use the List Rows action of DataVerse for this purpose.

Below is the configuration of my List Rows action.

statecode = 0 -> for Active Status
statuscode = 192350001 -> For Status Reason = Pending

The next step is to iterate through the retrieved records and update each record to the following values

  • Status -> Inactive
  • Status Reason – Cancel
  • Result -> Cancel
  • Completed On -> utcNow() (expression).

All set and done. Now when I run the flow, all the pending flow runs are now updated to Cancelled.

That’s great. The status is updated to Cancel. But remember that canceling an approval does not cancel the flow instances which are running.

When you cancel an approval, the approval will no longer be visible in the ‘Received‘ tabs of approval. If you go to the History tab, you will find the approvals marked cancel.

But any flow runs in running state will continue to be in running state. If you want to cancel all running instances of a Power Automate flow, check out my blog where I have demonstrated how to cancel all running instances of a Power Automate flow.

Hope you liked this post. If this post has helped, you can buy me a coffee.

For similar topics on Microsoft.NET and Power Platform, subscribe to my blog using the Subscribe option on right pane.

Debajit Dutta
Business Solutions MVP


Discover more from Debajit's Power Apps & Dynamics 365 Blog

Subscribe to get the latest posts sent to your email.

Discover more from Debajit's Power Apps & Dynamics 365 Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading