Advanced | Flow of the Week: Send parallel approval requests to a dynamic set of approvers

Almost all business processes have some form or another of approvals. These approvals apply to things like requests for vacation, overtime, or travel plans or for documents like budgets, contracts, blog posts, or specifications. The business process itself may need a single approval, sequential approvals, an everyone must approve type approval, or parallel approvals.

We recently added the ability to make Apply to each loops run in parallel as opposed to in sequence. This capability allows you to set up a parallel approval where the list of approvers is dynamic and determined when the flow runs. In this advanced FOTW post, we’ll walk you through an example.

The scenario

Let’s imagine that you are a SharePoint administrator for the world’s greatest imaginary company, Contoso. At Contoso, you have a document library that hosts documents for each of your departments – Finance, Legal, and Marketing. Each department has its’ own folder.

You also have a SharePoint list (‘Department Approvers’) that has the approvers for each department. Notice how Approvers is a multi-value people field where Finance has 3 approvers, Legal has 2 approvers, and Marketing has a single approver.  

Now, you want to create a Flow such that for a selected document, based on the folder path of the document (e.g. Finance), you will send an approval request to each of the department’s approvers (e.g. Dan Holme, Patricia Hendricks, and Alyssa Danesh). As soon as approver reviews the document, you want to notify the requestor, with the approver’s comments.

Let’s look at the Flow in detail. You can download it from here.

The trigger

To allow your end-users to start the workflow manually whenever they want to seek approval on a given document and provide runtime inputs like a Message to approvers, use the For a selected item trigger.

When invoked in SharePoint, end-users can see details about the Flow and enter a message via the Flow launch panel. (Learn more about the Flow launch panel)

Identify the folder Name

The For a selected item trigger returns the ID of the selected item, any runtime inputs specified (such as Message to approvers), and information about the invoker (such as User email and the Timestamp at which the flow was invoked).

To get more details about the selected file, use the Get item action and pass it the ID of the selected file.

Once you have the selected file, you can identify the name of the folder with an expression like the below and set a string variable called folderName.  

first(skip(split(body(‘Get_item’)?[‘{Path}’],’/’),2))

Determine the approvers

Having established which folder the selected file is located in, find the relevant approvers for that folder/department. Call the Get items action on the Department Approvers list (labeled as Get approvers by department below) and use an ODATA filter query such as Title eq ‘[folderName]’ with Top Count of 1. Next, initialize an array variable called Approvers. This array will be populated with approver emails.  

 

Since the Get approvers by department action returns an array of values (albeit of size 1), you’ll need to add an apply to each loop and iterate over the array. For each item, first Get the item properties (Get department approvers). Then, create another apply to each loop to iterate over Approvers (recall that Approvers is a multi-value people field) and append it to the Approvers variable (using the Append to array variable action).

 

 

For each approver

Finally, iterate over the Approvers array with another Apply to each loop. This loop contains a Start an approval action and a condition that sends an approval or rejection notification based on whether the Response is “Approved” or “Rejected”. Note – you can reference the currently selected item (approver in this case) using Current item attribute.

Parallel approvals

In order to ensure that all of the approvers receive their request at the same time, the For each approver loop must run in parallel. Click on the ellipsis menu of the loop and choose Settings.

Now override the Default and bump the degree of parallelism to the maximum. Note – the text incorrectly states that for each loops execute in paralell by default. They run in sequence by default.

Recap

In this blog post, we showed you how to send out dynamic parallel approval requests using the new concurrency control settings in for each loops. We also got a flavor for other Flow capabilities like variables, expressions, and ODATA filter queries.