Cancel approvals patttern

Cancel your pending approvals in Microsoft Flow

There are quite a few posts about approvals in Microsoft Flow. Have you ever noticed that when you have one of your flows sending an approval that there is no option to cancel the approval step?

No cancel option

In this post I’m describing one approach fro cancelling the approval steps so that you can resubmit the approval step.

Also, so far there isn’t an cancel approval step available yet in Flow. Hopefully it will arrive soon. So that I can avoid this pattern.

The Pattern

I’m going to start with the general pattern of the approval step and the cancellation of the same approval.

In my case the approval is initiated from a PowerApp. With the Create an approval I’m creating an approval.

This will create an entry within my common data services that presents the approval step to the user that needs to approve the action.

Then within my left branch I’m going to sit and wait for a response.

Cancel your pending approvals in Microsoft Flow 1

In the right branch I’m checking the current details of my approval task.

Get approval details

Once I get the details I set a variable to collect the current approval status. While waiting for a user to respond this will be set to Pending.

A Do until in the right branch will no check on a regular basis the status of my request again and again.

Cancel your pending approvals in Microsoft Flow 2

Now finally if the request was cancelled I need to terminate the flow that is running.

Cancel your pending approvals in Microsoft Flow 3

The terminate step in the above screenshot I’ve set to complete successfully. That way my flows will not fail.

Also note that the approval status is spelled Canceled rather than Cancelled.

Cancelling the request

To update the approval request in my Common Data Services, I’m creating a flow that takes an approval Id and then updated the Record in my CDS and marks it as cancelled.

In my case I’m using a flow to do this using the approval id from the request.

Cancel your pending approvals in Microsoft Flow 4

Please note that this approach may not be 100% supported as data in the CDS is directly updated

11 thoughts on “Cancel your pending approvals in Microsoft Flow

  1. commented on August 5, 2019 by Gennadiy

    Did you tested your “CANCELLING THE REQUEST” example?
    It does not work for me. the error:
    “192350006 is not a valid status code for state code msdyn_flow_approvalState.Active on msdyn_flow_approval with Id …”
    Any idea?

  2. commented on August 5, 2019 by Gennadiy

    Thanks for the quick answer.
    Numbers look OK:

    “_statecode_label”: “Inactive”,
    “msdyn_flow_approval_allowcancel”: false,
    “statuscode”: 192350006,
    “_statuscode_label”: “Canceled”,

    Could you PLS check if your example works and if so, please make a copy of your “Update a record” action. (Copy to clipboard (Preview))

  3. commented on August 6, 2019 by Gennadiy

    Hi Pieter,

    after spending some time It has worked also for me: I had to additionally update the following fields: “Completed On”, “Status value”: “Inactive” (!important), “Owner Type”: “systemuser”.

    Many thanks and cheers,

  4. commented on August 12, 2019 by Yanina

    Hi, i tried this solution but it didn’t work for me. Appers an error that says: “Principal user is missing prvWritemsdyn_flow_approval privilege”, i assume i have to give permission to the approvals entity… do you know where i have to give this permission?

    sorry for my english.

    • Hi Yanina,

      It will means that your account doesn’t own the approval step. It can also mean that your account isn’t an admin within your Dynamics databases.

  5. commented on March 4, 2020 by Elie

    How did you add the output under approval stage key? I’m not able to locate it .

  6. commented on April 8, 2020 by Martin

    Thanks for sharing. The issue I see with this stuff is it delays how quickly your approval reacts. With the do until limits for 5000 runs and 30 days, you can only check around every 10 minutes. So it’ll mean you could be waiting around for the flow to re check the attribute before the rest run, I want it instantaneous !

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: