Add multiple attachments to approval action in Power Automate
The approvals action has been very helpful for us, it has helped in designed many scenarios and has made tasks easier.
Recently there has been an addition to the approval action card wherein we can add attachments to the approvals. When we try to add a single attachment this works fine but when we have multiple attachments this is running into a FOR EACH loop causing the flow to re-run the approval action card multiple times.
Because of this user may receive multiple approval requests to overcome this behavior, I have found a way wherein we can add multiple attachments to the approval mail and this will not run into a FOR EACH loop. The steps for this are almost the same as how we try to add multiple attachments to an email.
Herewith I have created a flow with the below steps.
The flow is that when an item is created in a share point list with multiple attachments, add those attachments and send an approval including them.
Let start by adding a trigger – “When an item is created” and selecting the correct SharePoint Site and List.
Please ensure that you already have SP List created that allows storing multiple attachments on the items in it.
After adding the trigger, we need to fetch all the attachments added to the newly created list item. We should, hence, add the “Get attachments” action. The Site name and List name remain the same from the previous step. We want to then pipe the output “ID” from the trigger to the input ‘ID’ field.
Now, that we have a track on all the attachments – we must store these in a single array. Let’s start by initializing an array for the same
Now as we have initialized the array, in the next step we will fetch and store the contents of the attachment in the array. This is the main step that leads us to add multiple attachments, so be careful to follow the instructions.
Start by adding a “apply to each loop”, then chose the “body” output from the “Get Attachments”
Next, add “Get attachment content” action inside the loop. The SP site name and list name don’t change.
For the ID field – select ID output from the “When an item is created” trigger
For the file identifier field – Select the Id output from the “Get Attachments” action.
Next, we want to start adding to the array we just initialized. Set it up as shown below
For reference, I am showing the content that I have passed in the Append to array variable step again below.
"Name": Display name for the new file being created,
"Content":"Content of the file"
The content has to be enclosed in double-quotes(").
Our array contains the attachment item with two properties – Name and Content. We are assigning the DisplayName, retrieved from “Get Attachments” action to the Name property and the Attachment Content, retrieved from “Get Attachment Contents” action to the Content property.
Now for the final step, we need to send the approval email with the attachments array we just constructed.
This step is pretty simple, add an action to send the approval email and pipe in the attachments array output to the attachments input field.
That's all once you have successfully created and saved your flow, be sure to test it by exercising the trigger you should see an email as shown below in your inbox with multiple attachments send on single approval request.
Note: If you are getting an error when parsing the content of the attachment, please try converting the content into the base64 format using the base64() function in power automate.