How to Trigger a Workflow

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. 

Reassignment Flow

  • We need to trigger the workflow when a new request is created in the Approval Request Table
  • Change Type to AddedTable Name to Approval Request, and Scope to Organization. 

Approval Request

  • To get the workflow to look for the records from the workflow we want. Add an action to get a row by IDset the table name to Flow Approvals, and the Row ID to Approval ID Index. 

Flow Approvals

  • 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. 

Manually Trigger a Flow

  • 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.

Row Filters

  • 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. 

Get Row From Approvals

  • 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. 

Flow Name

  • 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. 

List Records

  • 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.
     

Trigger a Workflow

  • 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. 

Get Previous Owners

  • Add an action to get a Row by ID, set the table name to Users and Row ID to the previous requests’ Owner value. 

Get Record - Previous Owners

  • 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. 

Compose Workflows

  • 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. 

Inputs & Outputs

  • 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.

Get Items

  • Add an action to Get Items information, set the Site Address to your SharePoint siteList Name to your list name, and ID to the output of Get Items ID.

Get Items Output

  • 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 ItemStatus Value to Reassigned, and Approver Claims to Primary Email from Get Record – Get Current Owner. 

Update Items - Trigger a Workflow

Note: Remember to change the Flow Name to equal the Flow ID from the workflow that’s been run on the SharePoint list. 

Learn More

Want to discover more about Power Automate? Read more here

Learn more concepts like Triggering a Workflow, through our Power Up with Power Apps Series.

Contact us to get started or learn how you can implement and use the Power Automate for maximum efficiency and productivity.