Welcome to our blog where will be sharing tip, tricks and detailed walk-throughs covering all areas of Dynamics 365 but primarily focused on the Field Service and Project Service Apps, Scheduling and integration using Microsoft Flow and the Common Data Service (CDS). We hope you find the blog posts useful and please feel free to comment if you would like us to elaborate on any particular area. 

Dynamics 365: How to remove redundant Flow Approvals for a user

There have been quite a few blogs recently around the use of the Approvals process in conjunction with Dynamics 365 and I've seen a few questions asking how to remove redundant Flow Approval Requests from a users Approval dashboard whether it be in the web or mobile app.

These Flow Approvals could vary from approval from Time Entries & Leave Requests to Invoices & Purchase Order Approvals, but what happens if the user or person who initiated the approval process wants to recall/delete the approval request because maybe they've made a mistake or the request is no longer valid.

There is a way to do this but it's well hidden. Firstly, if you aren't already aware once you have set up Flow Approvals to work with Dynamics 365, you will see a number of new entities created for you within your Dynamics 365 instance which can be viewed in the default solution.

All in all, there are 6 new entities:

  • Approval

  • Approval Request

  • Approval Response

  • Await All Approval Model -

  • Basic Approval Model Data

  • Flow Approval

I'm not going to go into too much detail on these as you can play around with how they work by just creating Flow approvals in Dynamics 365 but the entity we're particularly interested in is Approval (msdyn_flow_approval) because this is the of the approval records that is created when an approval is started from Flow and which contains an all important field, Item Link, which you specify in the Flow when you build the approval. Not only that but it appears that this is also the record which is referenced for display by the Approval Mobile and Web Apps.

This field is key because without it I could not find any way to link the entity I made the approval request on with the actual approval in Flow. Therefore, if you want to have the ability to be able to remove Approvals from an Approval Users Mobile App or Web App Dashboard when they are no longer valid you need to populate the Item Link field when creating the Approval. Typically, this will be a URL to the record in Dynamics 365 which is requesting approval.

In my case I was using Flow to do a multi-stage approval for an Expense & Time Entries in Dynamics 365 PSA but when the users choose to recall the Expense or Time Entry to adjust/remove it, the Approval record still appeared in the Approvals Web App and Flow Mobile App although it was no longer valid, essentially now an orphaned approval.

For my example, I'm going to stick with something a little more simple, a basic single approval for Time Off Requests in Field Service. We are going to create 2 Flows, one to do the Approval and one to remove it when the user deletes who made the request deletes it (for time entries and expenses this would probably be on a status update when the user recalls the entry).

The first flow is triggered when a Time Off Request is created and checks to see if the Bookable Resource Time Off Requests require Approval. If it does, it starts the Approval process assigning it to the Manager of the Resource and then performs certain actions depending on whether Approved or Rejected. I've broken it down into 2 screenshots as I couldn't fit it in one!

The all important part here is ensuring the item link ends with id={Guid} as this is what we are going to use to check for matching approvals when the Time Off Request is deleted.

So, the second Flow looks like the screenshot below with a check to see if there are any non-complete Approvals for the Time Off Request being deleted.

So, if we look at this in action. First let's create the Time Off Request.

Creating this triggers the Flow to start the Approval and it appears in Approvals Dashboard and Flow Mobile App. Note, the Item Link is populated and has the id={Guid} at the end of link which we will use to search for matching approvals on Time Off Request deletion.

Now delete the Time Off Request before it is approved

Flows run on Delete of Time Off Request and removes the Approval record.

Refresh the browser in the Flow App and select Approvals (just clicking on and off won't work as it doesn't refresh the dashboard). Et voila, the Approval has disappeared :)

I hope you found this useful and just before we finish there is an important thing to note below..

IMPORTANT NOTE: although this will remove the Approval Request from the users Mobile and Web App it will not actually stop the Flow. Therefore, there are a number of options, either reduce the timeout accordingly on the "Start Approval" action or add a parallel branch to check periodically (every hour maybe) if the Flow Approval record still exists in Dynamics 365 and if not, Terminate the Flow.

In addition, I'm not sure if Microsoft would necessarily advocate this approach but it was the only way I could find to remove orphan requests and prevent them from clogging up the Approvers dashboard.

718 views0 comments