Power Up With Power Apps – How To Trigger a Workflow When an Approval is Reassigned
How to Trigger A Workflow When An Approval is Reassigned
Power Automate is just that, it is all about automation. Microsoft developed Power Automate as a service to help people create automated workflows between their favourite apps and Microsoft-based products. By implementing this, organizations and users have been able to save a great deal of time when doing tasks, enabling them to focus on what matters most.
Power Automate continues to evolve and equip teams to synchronize files, get notifications, collect data, and more, with greater efficiency, boosting productivity within organizations.
In this article, we will cover how to Trigger a Workflow When an Approval is Reassigned.
Triggering a Workflow
There is currently no way for businesses to track if an approval workflow has been reassigned to another user and then to write that information back to their approval workflow log.
Only the user that sent the approval request can see with whom the approval is waiting in their Approvals Center in Power Automate.
We can now trigger another workflow that will search the Dataverse, filter it for reassigned workflows and get the necessary information to write back to the approval log.
When we create an approval in Power Automate, a record is created in the Flow Approval table, a record or records depending on if there are multiple approvers assigned is also created in the Approval Request table. We can track this approval by its Approval ID and look up its Request ID and User information in the Dataverse.
- To get started go to Power Automate and create a new flow.
- Select Automated cloud flow, give your flow a name.
- Choose “When a row is added, modified or deleted” as your flow’s trigger and click on Create.
- We need to trigger the workflow when a new request is created in the Approval Request Table.
- Change Type to Added, Table Name to Approval Request, and Scope to Organization.
- To get the workflow to look for the records from the workflow we want. Add an action to get a row by ID, set the table name to Flow Approvals, and the Row ID to Approval ID Index.
- Save the flow.
- Quickly create another button flow that starts and waits for approval for testing purposes.
You can set the Approval Type to be first to respond, give it a Title and assign a user to the Assigned to field.
- Save and run the flow, this will create an approval request and trigger our reassignment flow as well.
Note: The reassignment flow will now trigger every time an approval request is created, to only get it to trigger when an approval request is reassigned, we will add a filter condition.
- Running the flow will give us an insight into the data that is fetched from the Dataverse. Click into the run history and then on the first action click on the show raw outputs.
- Here we can see “msdyn_flow_approvalrequestidx_reassignedfromid”: “<none>”. This means that this flow has not been reassigned. Reassigned flows have a GUID in place of <none>.
- We will edit the flow trigger and add “msdyn_flow_approvalrequestidx_reassignedfromid ne ‘<none>’” to the Row filter because we only want it to trigger when there is a GUID present in this field.
- To get the Approval information like the Title of the request we will search the Approvals table in the next step.
- Add an action to get a row by ID, set the Table name to Approvals, and the Row ID to Approval ID Index.
- Next, we will add a Condition to check if the request added is from the workflow we need the log for.
- Check if the Flow Name field from the Flow Approvals action is equal to the flow ID.
- You can get this Flow ID by going back to your button flow, click on the URL and copy everything after “flows/”.
- In the Yes condition, we will first get the Current user the workflow has been reassigned to.
- Add an action to List rows from the Approval Request table, Filter rows by “msdyn_flow_approvalrequestidx_approvalid eq ‘Approval ID Index’”, Sort by “msdyn_flow_approvalrequest_lastnotifiedon desc” and set the Row count to 1.
- Once we’ve got the record we are looking for we can get the reassigned user information.
- Add an action to get a Row by ID, set the table name to Users and Row ID to the output of current requests’ Owner value.
- We will repeat the same steps to get the Previous user that reassigned the workflow.
- Add an action to get a Row by ID, set the table name to Approval Requests and Row ID to the output of current requests’ Reassigned from value.
- Add an action to get a Row by ID, set the table name to Users and Row ID to the previous requests’ Owner value.
- We now have all the necessary information for a log.
- For testing purposes, you can add a compose action to check the information you get.
- The first part of the compose action gets its information from Previous Requests and Previous Owners. The second part gets its information from Current Requests and Current Owners.
- Save and run the button flow again and this time reassign the approval to another user.
- Once the flow has run successfully your Compose Action’s output should look like this.
- You can now connect this to a list in SharePoint where you are requesting approvals.
- Add an action to Get items, set the Site address to your SharePoint site, List Name to your list name, add a Filter query where the Title eq. ‘Title’ from the Approvals table, and set the Top count to 1.
- Add an action to Get Items information, set the Site Address to your SharePoint site, List Name to your list name, and ID to the output of Get Items ID.
- When the approval is reassigned, we want to update the Approver Claims field and the Status Value field.
- Add an Update item action to the end of your Yes condition, set the Site address to your SharePoint site, List Name to your list name, ID to ID from Get Item, Title to Title from Get Item, Status Value to Reassigned, and Approver Claims to Primary Email from Get Record – Get Current Owner.
Note: Remember to change the Flow Name to equal the Flow ID from the workflow that’s been run on the SharePoint list.
- Accounting / Finance (33)
- Atlassian (2)
- Budgeting & Costing (20)
- Business Applications (19)
- Business Intelligence (25)
- Cloud (8)
- Collaboration & Sharing (13)
- Company News (22)
- Corporate Performance Management (21)
- Dynamics 365 Business Central (19)
- Dynamics CRM (13)
- Dynamics GP (42)
- Enterprise Resource Planning (10)
- Events (8)
- GP Add-Ons (1)
- Leadership/Business Management (8)
- SharePoint (18)
- Talent Management (9)