Attachments In Power Automate Approvals

Introduction

 
Recently we had a requirement where the list attachments should be shown in the approval action in Power Automate, this way the users/approvers can verify the requested content in the approval email itself without changing the context or navigating to the site. Here the attachments are of very less (<20 MB). The below steps should work for either single or multiple attachments.
 
We can set attachments in Email actions as well as approval action. We will investigate both the scenarios.
 

Sending attachment in Email

 
This is a straightforward approach. You can look into step by step in the this article. Thanks to Sarvesh.
 

Sending attachments in Approval

 
Before I start the steps, I should thank Alex from It Ain’t Boring’ who wrote a brilliant post on ‘Attachment to CDS’. He gave a pointer on how to configure the attachment array in which Power Automate understands. I have mentioned the URL in the ‘References’ section. Hatsoff Alex!!! 
 
Step 1
 
Browse to the list where you need to create a flow, and select Automate --> Create a flow as shown in below screen capture. 
 
Power Automate Sending Attachments
 
Step 2
 
From the modern UI ribbon select ‘Power Automate’ and click on the ‘Create Flow’. Lets use the template for this demo ‘Start approval when a new item is added’.
 
Power Automate Sending Attachments
 
Step 3
 
Select continue after the initial configuration.
 
Power Automate Sending Attachments
 
Step 4
 
To keep this demo simple I am removing the error handling block from the template.
 
Power Automate Sending Attachments
 
Step 5
 
You should see something like this, after collapsing all the actions.
 
Power Automate Sending Attachments
 
Step 6
 
Try getting the attachments of the request, after the trigger and configure the ‘Get Attachments’ action like below. ID should be ID of item when 'New Item is created'. 
 
Power Automate Sending Attachments
 
Step 7
 
After initializing variable add the ‘Get attachment content’ action as shown in below screen capture.
 
Power Automate Sending Attachments
 
Step 8
 
You will have the following set up. Please note that once the values are configured the foreach block is automatically added.
 
Power Automate Sending Attachments
 
Power Automate Sending Attachments
 
The final action should look like below
 
Power Automate Sending Attachments
 
Step 9
 
Inside an ‘Apply to Each’ block add an action ‘Append to an array variable’
 
Power Automate Sending Attachments
 
Step 10
 
This is the crucial part. Observe commands carefully.
 
For the Name field chose the existing array variable ‘attachmentArray’ that is initialized before.
 
Power Automate Sending Attachments
For the Value input the following JSON carefully.
  1. {  
  2.    “name”:  
  3.    “content”:  
  4. }   
For the “name” field the dynamic value should be as configured in below screen shot.
 
Power Automate Sending Attachments
 
For the “value” field the configuration do the following very carefully.
  • In the expression add ‘Attachment Content’ and the expression should be body(‘Get_attachment_content’). After that append ?[‘body’]. The reslut expression should be
body(‘Get_attachment_content’) ?[‘body’].
Power Automate Sending Attachments
  • Now encapsulate the entire expression with braces. It should look like (body(‘Get_attachment_content’) ?[‘body’]).
     
  • In the expression window type base64 and encapsulate the resultant expression inside base64 function. It should look like base64(body(‘Get_attachment_content’) ?[‘body’]).
  • Now the final step in expression replace body with ‘outputs’. It should looks like
    base64(outputs(‘Get_attachment_content’) ?[‘body’])

    Power Automate Sending Attachments
Step 11
 
The final value should be in JSON format as shown below. 
 
Power Automate Sending Attachments
 
Step 12
 
Now select the approval action ‘Start and wait for an approval’. You need to delete the default approval that comes with the template and configure as per below screen shot. 
 
Power Automate Sending Attachments

Step 13
 
In the condition action update the condition ‘Outcome’ is equal to ‘Approve’.
 
Power Automate Sending Attachments
 
Step 14
 
validate the final approval action, it should look like below
 
Power Automate Sending Attachments
 
Step 15
 
Validate the final flow and test it
 
Power Automate Sending Attachments
 
Step 16
 
Validate the attachments in the approval email
 
Power Automate Sending Attachments
 

Conclusion

 
Thus in this article, we have seen how to configure PowerAutomate to send attachments in approval action.
 
References
  • https://powerusers.microsoft.com/t5/General-Power-Automate/Power-Automate-approval-with-Attachments/td-p/415327/page/2?lightbox-message-images-829975=224948iF612FF35BBDE1435
  • https://www.itaintboring.com/dynamics-crm/power-automate-flow-creating-an-email-with-attachment-in-cds/