Power Automate

The Hidden Multi Level Approval Feature in Power Automate

The Hidden Multi Level Approval Feature in Power Automate Posted by - Matthew Devaney on - May 19, 2024 77 Comments A multi level approval in Power Automate ...

Matthew Devaney
Published
Reading time
7 min read

Before you start

Is this guide for you?

Best entry point
Power Automate
Time investment
7 min read

Imported reference from Matthew Devaney's blog for learning purposes. Original: https://www.matthewdevaney.com/the-hidden-multi-level-approval-feature-in-power-automate/. Author: Matthew Devaney.

The Hidden Multi Level Approval Feature in Power Automate Posted by - Matthew Devaney on - May 19, 2024 77 Comments

A multi level approval in Power Automate can be used to send an approval request to a 1st level approver, 2nd level approver and more. The approval action returns a final outcome of either accepted or rejected and a full history of each approvers response with a timestamp. The Approvals connector does not include a standard action for sequential approvals. However, we can use the Invoke an HTTP Request action to create a multi level approval in a Power Automate flow. Table of Contents

Introduction: The Multi Level Invoice Approval Flow

Setup The Invoice Approvals SharePoint List

Trigger The Approval Flow When A File Is Created Get The User Profile For Each Approver

Make A Connection To Microsoft Teams Approvals

Create A Multi Level Approval Using An HTTP Request

Wait For The Multi Level Approval To Be Completed

Record The Approval Outcome And Approval History In SharePoint Test The Multi Level Approval Flow

Sample Code: Create An Approval HTTP Request

Introduction: The Multi Level Invoice Approval Flow

Employees at a construction company use a mutli level approval process to approve vendor invoices for payment. A Power Automate flow sends the 1st level approval request to a Project Coordinator and the 2nd level approval request to the Project Manager.

The multi level approval status is tracked in a SharePoint document library. A full history of the approvals process is recorded including request and responses dates.

Setup The Invoice Approvals SharePoint List

Create a new SharePoint document library to store invoices, track the invoice status and the approval history with the following columns: Name

Invoice Status (choices: Submitted, Approved, Rejected)

Approval History (multiple lines of text)

Trigger The Approval Flow When A File Is Created

Open make.powerautomate.com and create a new automated flow. Select the SharePoint – When A File Is Created (Properties Only) trigger and target the Invoice Approvals document library.

Once the approvals flow begins we want to mark the document with a status of Submitted to indicate the approvals process has started. Add a SharePoint – Update File Properties action, use the ID from the trigger and set the Invoice Status Value to Submitted . Get The User Profile For Each Approver

Every user in Office 365 is assigned unique identifier. We must obtain the ID for each approver in order to send them an approval.

Create an Office 365 Users – Get User Profile action and input the email address of the 1st level approver. Then insert a 2nd Office 365 Users – Get User Profile action and supply the email address of the 2nd level approver. These actions will return the full user profile for each approver including their ID, display name, job title, location and much more.

Make A Connection To Microsoft Teams Approvals

A multi level approval is not available as part of the Microsoft Teams actions included in Power Automate. We will use the HTTP With Microsoft Entra ID (Pre-authorized) – Invoke An HTTP Request action to create an approval instead.

Upon adding the action we will be asked to setup a connection.

Use the following URL in both the Base Resource URL and Microsoft Entra ID Resource URI fields and press the Sign In button. https: //approvals.teams.microsoft.com Code language: JavaScript ( javascript )

Create A Multi Level Approval Using An HTTP Request

Once the connection is setup we can configure the Invoke An HTTP Request action to create an approval.

Select the following method to indicate the HTTP request will create approvals records. POST

Use this URI to access the create approvals endpoint. /api/CreateApproval

Include an Accept header and use this code in the value field application/json

Then copy and paste this code into the body of the Invoke An HTTP Request action. Make to rename actions added to the flow so far match the screenshots in this tutorial to ensure the dynamic values do not result in an error.

The Steps property defines who should receive the approval and which order they should receive it in. This example only included two approvals but more can be added using the same object structure.

TextAttachments stores the location of the document to be approved in the NoteText field along with a display name in the Subject property. { "Title" : "Invoice Approval" ,

"Details" : "An invoice is ready for your approval." , "ApprovalType" : 0 , "Type" : 5 , "Creator" : 0 , "AssignedTo" : [], "ApproverNames" : [], "TextAttachments" : [ {

"Subject" : "@{triggerOutputs()?['body/{FilenameWithExtension}']}" ,

"NoteText" : "@{triggerOutputs()?['body/{Link}']}" } ], "Steps" : [ { "AssignedTo" : [

"@{outputs('Get_user_profile_(V2):_Approver_1')?['body/id']}" ], "ApprovalPolicy" : 1 , "ApproverNames" : [

"@{outputs('Get_user_profile_(V2):_Approver_1')?['body/displayName']}" ] }, { "AssignedTo" : [

"@{outputs('Get_user_profile_(V2):_Approver_2')?['body/id']}" ], "ApprovalPolicy" : 1 , "ApproverNames" : [

"@{outputs('Get_user_profile_(V2):_Approver_2')?['body/displayName']}" ] } ],

"FlowEnvironment" : "@{workflow()?['tags']?['environmentName']}" } Code language: JSON / JSON with Comments ( json )

Wait For The Multi Level Approval To Be Completed

An multi level approval flow becomes completed when all approvers in the sequence have responded with “Approve” or any single approver responded with “Reject.”

Add an Approvals – Wait For An Approval action and use this expression to fill-in the Approval ID field.

body( 'Invoke_An_HTTP_request:_Create_Approval' )?[ 'ApprovalId' ] Code language: JavaScript ( javascript )

Then add a Data Operations – Compose action and write this expression to determine whether an approvals flow had an outcome of Approve or Reject.

trim(last(split(body( 'Wait_for_an_approval' )?[ 'outcome' ], ',' ))) Code language: JavaScript ( javascript )

The outcome of an approval is returned as comma separated text. We must use the split, last and trim functions to get the final value without any whitespace.

Record The Approval Outcome And Approval History In SharePoint

The approval outcome and approvals history should be stored in SharePoint when the approvals process is finished. Add a new Condition to the flow where the Compose action is equal to Approve. Then insert a SharePoint – Update File Properties action to the If Yes block and set the Invoice Status Value to Approved. Do the same for the If No block but change the Invoice Status Value to Rejected.

Use this code in the Approval History field for both SharePoint – Update File Properties actions to record the approvals history.

body( 'Wait_for_an_approval' )?[ 'responseSummary' ] Code language: JavaScript ( javascript ) Test The Multi Level Approval Flow

We are now finished building the multi level approval flow. Save and test the flow to ensure it works.

The 1st level approval response is sent to the Project Coordinator named Mary Baker.

When Mary approves the invoice the 2nd level approval is sent to the Project Manager Matthew Devaney.

Once Matthew approves the invoice status is set to approved and the approval history is recorded alongside the document in SharePoint.

Sample Code: Create An Approval HTTP Request

For reference, here is the HTTP request body needed to create the multi level approval showing what the dynamic values evaluate to. This code can be modified to add more approval levels if you require it. Sample code: { "Title" : "Invoice Approval" ,

"Details" : "An invoice is ready for your approval." , "ApprovalType" : 0 , "Type" : 5 , "Creator" : 0 , "AssignedTo" : [], "ApproverNames" : [], "TextAttachments" : [ { "Subject" : "Adatum 1.pdf" ,

"NoteText" : "https://matthewdevaney.sharepoint.com/sites/MatthewDevaneyBlog/Invoice%20Approvals/Adatum%201.pdf" } ], "Steps" : [ { "AssignedTo" : [ "34a4e2c8-6020-4421-92ca-e04a4a29edfe" ], "ApprovalPolicy" : 1 , "ApproverNames" : [ "Mary Baker" ] }, { "AssignedTo" : [ "6857d910-10c3-485e-a492-6456ce2f1625" ], "ApprovalPolicy" : 1 , "ApproverNames" : [ "Matthew Devaney" ] } ] } Code language: JSON / JSON with Comments ( json ) Did You Enjoy This Article? 😺

Subscribe to get new Copilot Studio articles sent to your inbox each week for FREE Enter your email address Sign Me Up Questions?

If you have any questions or feedback about The Hidden Multi Level Approval Feature In Power Automate please leave a message in the comments section below. You can post using your email address and are not required to create an account to join the discussion. Matthew Devaney Power Automate

Save Docusign Document To SharePoint With Power Automate

Share this

Tagged

Approvals · Power Automate

Have a Microsoft 365 topic idea?

Share article suggestions, community session ideas, corrections, or real-world scenarios for future nxtM365 learning notes.

Suggest a topic

Keep learning Microsoft 365

Explore more practical guides for SharePoint, Power Platform, Copilot Studio, migration, automation, governance, and security.

Continue learning

Next action

What to do next

Browse all tutorials →