Cancel an Approval of Behalf of Another User in Power Automate

Cancel an Approval of Behalf of Another User in Power Automate

Using the Approvals Connector within Power Automate is a great way to streamline approvals, as it provides a lot of functionality out of the box. One limitation it has however is the ability to cancel an approval on behalf of another user. For that, we need to use Power Automate and make an update directly in the Approvers table record.

Example – Purchase Order Approval Request

Using a Model Driven App, I have an IT Inventory tracking system where I need to submit Purchase Orders for manager approval. When the flow button is pressed in the app, the approval is triggered. For this scenario, the approval needs to be canceled because the manager is unavailable and will be resubmitted later.

Several key pieces of data must be known for the approval request to be successfully canceled:

  1. Approval ID – This is the primary key GUID that is generated once the “Create an Approval” action is triggered successfully.
  2. Workflow ID and Name – These correspond to the Power Automate run ID and GUID name of the approval flow run.

Create the Approval

I store the aforementioned data elements in a custom table called ‘PO Approvals’ and link the record to the purchase order record.

The main approval actions
The Approval Id is written to a custom column in this table called “Approval Record Id” Same goes for the workflow name an id.

Use an expression to set the WorkflowRunId workflow().run.name and WorkflowRunName as workflow().name respectively.

Don’t use the Create and Wait for an Approval action because we wouldn’t be able to retrieve the approval ID until after the user approves. Hence, why Create an Approval is used, update the custom PO Approvals table, then wait for approval.

Cancel the Approval

With the flow awaiting approval, I will cancel it on behalf of the manager by triggering another Power Automate flow. To trigger it, I am setting a boolean flag field of “Cancel Approval Request” to yes. The flow will fetch the PO Approval Record associated with the order.

This flow will only trigger when the field is set to true

Then, it’s a matter of using the approval id stored earlier to update the following settings.

  • Stage: Complete
  • Status Reason: Canceled
  • Result: Canceled
  • Completed On: Use the function utcNow()
  • Status: Inactive
Loop through the one or more pending approvals for this PO; getting the Approval record using the Approvals Id stored earlier.

Be sure to click “Show Advanced Options” to set the remaining settings

Those settings will cancel the approval. But we’re not quite done! The original approval flow is still awaiting the approval response which will no longer come, so it’s best to cancel the original flow run. Using the Power Automate Management Connector, we can pass the workflow name and id we also captured earlier.

You can make the environment value more dynamic for ALM purposes by using the expression workflow()?['tags']?['environmentName'] to get the current environment id

And if go back to the Approval flow, we’ll see canceled. If the original approval goes into their Approvals Center in Power Automate, it’ll also reflect cancelled.

Flow Run History
What the approver sees in their Approvals Center in Power Automate

And there you have it! You could do this work-around with a SharePoint based solution, but be aware your Power Automate would still need to touch Dataverse for the Approvals table update which requires the flow to be licensed for premium! I hope in the future, Microsoft will bring this ability directly into the Standard approvals connector.

Leave a Reply