Cancel approval tasks in Flow

Posted by

I recently finished a large Power Automate implementation that had a long UAT period.

As expected, after the UAT was completed, we had thousands of approval tasks sitting in the worklist of the testers. We also had a feature that would recreate any approval tasks that had expired.

The testers would receive notifications from tasks created 3 months back and also clutter their Power Automate Approvals dashboard.

So, I was asked if I could get rid of the approval tasks that were pending.

There are two ways to achieve this.

1) Using PowerShell API

Connect-PnPOnline -Url "Your Site Url" -Interactive
Run this to get a list of Flow environments
$Requests = Get-FlowApprovalRequest -EnvironmentName "Flow Environment Guid"
foreach($Request in $Requests) {
Deny-FlowApprovalRequest -EnvironmentName "Flow Environment Guid" -Comments "Cancelled" -ApprovalId $Request.ApprovalId -ApprovalRequestId $Request.ApprovalRequestId

2) Using Flow, by updating the Dataverse Approvals table

Approvals are stored in the Dataverse Table named “Approvals”.

Here is a flow that I built to update the records directly in Dataverse.

Note: Please look at the flow logic before implementing. I am cancelling ALL flow approvals for ALL people

Leave a Reply

Your email address will not be published. Required fields are marked *