Parallel Archives - Microsoft Power Platform Blog Innovate with Business Apps Wed, 23 May 2018 18:52:54 +0000 en-US hourly 1 Intermediate | Flow of the week: Approval reminders using parallel branches http://approjects.co.za/?big=en-us/power-platform/blog/power-automate/approval-reminders-using-parallel-branches/ Wed, 23 May 2018 18:52:54 +0000 This post will introduce parallel branches as a way to achieve concurrent Flow logic. It shows how to use parallel branches to send periodic reminders to approvers that stop once the approval is completed.

The post Intermediate | Flow of the week: Approval reminders using parallel branches appeared first on Microsoft Power Platform Blog.

]]>
A common requirement from our customers is to send periodic reminder emails to approvers about pending requests. This post will show how to achieve this using Flow parallel branches. For those unfamiliar with parallel branches, they are a built-in mechanism for a Flow to perform multiple actions simultaneously. (For readers with programming experience, they are analogous to multi-threaded programming). We’ll use one branch to perform the “Start an approval action”, and another branch to wait for the approval to complete, and periodically send emails.

For our scenario, I’ll have a set of approvers that need to acknowledge via Flow approval when files are added to a document library. After adding the “When a file is created (properties only)” trigger, I’ll add two “Initialize variable” actions. One will initialize a boolean approvalDone variable to false, and the other will set up my list of approvers. I’ll explain why I need these two variables in more detail a bit later in the post.

Initializing variables and trigger

Next I’ll add the “Start an approval action” and hook up the inputs. I’ll take the list of approvers from my variable, and reference the link to the file that was just uploaded. 

Now that I have the approval action card configured, I need to set up the parallel branch — the actions I want to happen while the approval is in progress. I’ll hover the mouse ABOVE the “Start an approval card” and click the + sign, find “Add a parallel branch”, and select “Add an action”.

Adding parallel branch before approval

The Flow designer will now fork the execution arrow into two branches, placing the approval card on the left and bringing up the connector/action dialog on the right. This is to help us visualize that both forks will execute simultaneously

Forked flow execution

Before we can start adding the reminder logic on the right side of the fork, I need to add one more action on the left after the approval. Remember that we initialized a boolean approvalDone variable? After the “Start an approval” action, I’ll add a “Set variable” to update this variable to true — this will be used to “signal” to the other branch that the approval is completed, and no more notification reminders need to be sent. (Without doing this, we might continue to send mails indefinitely!)

Setting done variable

Now we can focus on the reminder aspect. I don’t want to remind the approvers as soon as the approval is created (they have the Flow actionable approval email for that), so I’ll add a “Delay” action to give them a whole day to approve. Once the day is up, I now want to loop until the approval is complete. I’ll use “Do Until”, where the exit condition is the approvalDone variable becoming true. The variable will be checked at the start of every loop iteration, and once the approval is complete and variable set to true, it won’t execute another iteration. (Note that based on how long you expect the approval to be active, and how often you want to send reminders, you may need to adjust the limits on the “Do Until” to make sure it gives you enough retries). 

Sleep before loop

The first action we’ll do in the loop is to send the email, so I’ve set up a basic “Send an email” using Office 365 that includes the link to the file and a friendly reminder message. I can use the approversList variable to make sure that the email is sent to the same set of people to which the approval is assigned. After the email is sent, I want to wait again before sending it again. I’ll Delay for another day, but you could just as easily do something custom — send more frequent reminders after a while, cc their manager after some number of reminders, check if the day is a holiday/weekend, etc.)

Because the loop will check the condition before executing, if the approvers respond during any of the “Delay” actions, the condition will be checked again before sending either the first or subsequent reminder emails. This avoids sending reminders for approvals that are already complete.

Email then sleep

If you wish to play around with this technique, I exported the sample flow so you can import it into your environment. It can be downloaded here

Parallel branches are a powerful approach to extend a single Flow with business logic/behavior that needs to run concurrently, without splitting logic across multiple Flows. 

The post Intermediate | Flow of the week: Approval reminders using parallel branches appeared first on Microsoft Power Platform Blog.

]]>
Advanced | Flow of the Week: Send parallel approval requests to a dynamic set of approvers http://approjects.co.za/?big=en-us/power-platform/blog/power-automate/advanced-flow-of-the-week-send-parallel-approval-requests-to-a-dynamic-set-of-approvers/ Fri, 30 Mar 2018 12:59:36 +0000 In this advanced FOTW post, learn how to create dynamic parallel approval requests using the new concurrency control settings in for each loops and also get a flavor for other Flow capabilities like variables, expressions, and ODATA filter queries.

The post Advanced | Flow of the Week: Send parallel approval requests to a dynamic set of approvers appeared first on Microsoft Power Platform Blog.

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

 

The post Advanced | Flow of the Week: Send parallel approval requests to a dynamic set of approvers appeared first on Microsoft Power Platform Blog.

]]>