Tuesday, January 21, 2025

How to do the approval requests to be sent concurrently rather than sequentially to ensure all 53 recipients receive their emails independently and without delay.

Problem Statement

I am working on automating the process of sending leave resumption notices to staff to confirm their return. Currently, I am using the "Get Items" action to retrieve a list of items from a SharePoint list. However, I am encountering an issue with the approval workflow within the "Apply to each" action.

Challenge:

For each of the 53 items retrieved from the SharePoint list, I need to trigger 53 independent approval requests, each sent to the corresponding recipient’s email address (one per item). The current setup processes these requests sequentially, causing the flow to wait for each approval email to complete before proceeding to the next item. This results in delays.

Objective:

I need the approval requests to be sent concurrently rather than sequentially to ensure all 53 recipients receive their emails independently and without delay.

I’d appreciate any guidance or best practices to achieve this.
---------------------------------------------------------------------

To achieve concurrent approval requests in Power Automate for each item retrieved from a SharePoint list, you can use a parallel branching approach. Below is a general outline of how you can set this up in Power Automate:

Solution Outline

1.    Trigger: Use a trigger to start the flow, such as "When an item is created" or "When an item is modified" in the SharePoint list.

2.    Get Items: Use the "Get items" action to retrieve all the items from the SharePoint list.

3.    Apply to Each: Use the "Apply to each" action to iterate over the retrieved items.

    • Inside the "Apply to each" action, use the "Start and wait for an approval" action.

4.    Concurrency Control: Adjust the concurrency control settings of the "Apply to each" action to allow parallel processing.

Step-by-Step Guide

Step 1: Create a new Flow

  1. Go to Power Automate (https://flow.microsoft.com/).
  2. Click on "Create" and select "Automated flow".
  3. Choose a trigger, such as "When an item is created" or "When an item is modified" for your SharePoint list.

Step 2: Get Items from SharePoint

  1. Add a new action and search for "SharePoint".
  2. Select the "Get items" action.
  3. Configure the "Get items" action to point to your SharePoint list.

Step 3: Apply to Each

  1. Add an "Apply to each" action.
  2. Set the "Output" field to the value from the "Get items" action (usually value).

Step 4: Start Approval Process

  1. Inside the "Apply to each" action, add a "Start and wait for an approval" action.
  2. Configure the "Start and wait for an approval" action:
    • Set the "Approval type" to "Approve/Reject - First to respond".
    • Set the "Title" and "Assigned to" fields accordingly (e.g., use dynamic content to assign to the appropriate email address).

Step 5: Enable Concurrency Control

  1. Click on the "Apply to each" action to open its settings.
  2. In the settings pane, turn on "Concurrency Control".
  3. Set the "Degree of Parallelism" to a suitable number (e.g., 20). This number controls how many approval requests can be processed concurrently.

Step 6: Save and Test the Flow

  1. Save the flow.
  2. Test the flow by creating or modifying items in the SharePoint list.

Example Flow Configuration

Here is an example of how the flow might look:

  1. Trigger: When an item is created in SharePoint.
  2. Get Items: Retrieve items from the SharePoint list.
  3. Apply to Each:
    • Start and Wait for an Approval:
      • Title: "Leave Resumption Approval"
      • Assigned toitem.email (Use dynamic content to assign to the recipient's email).

PowerShell Solution

If you prefer to use PowerShell, you can use the PnP PowerShell module to retrieve the items and send approval emails. Below is an outline of the PowerShell script:

Install PnP PowerShell Module

PowerShell

Install-Module -Name PnP.PowerShell -Force

PowerShell Script

PowerShell

# Connect to SharePoint
Connect-PnPOnline -Url "https://yourtenant.sharepoint.com/sites/yoursite" -Interactive
 
# Get items from SharePoint list
$items = Get-PnPListItem -List "YourListName"
 
# Loop through each item and send approval email
foreach ($item in $items) {
    $email = $item["Email"]
    $subject = "Leave Resumption Approval"
    $body = "Please approve the leave resumption for " + $item["Title"]
 
    # Send approval email
    Send-MailMessage -To $email -Subject $subject -Body $body -SmtpServer "smtp.yourserver.com"
}

Summary

Using Power Automate with parallel branching or PowerShell with a loop, you can send concurrent approval requests to each recipient. The key in Power Automate is to enable concurrency control in the "Apply to each" action. This ensures that all recipients receive their approval requests independently and without delay.


No comments:

DeepSeek vs OpenAI

DeepSeek vs OpenAI Two companies have recently drawn a lot of interest in the quickly changing field of artificial intelligence (AI): Op...