Assign approval task with multiple (0 – n) attachments in Power Automate
Posted On November 8, 2020
“I need for the approver to be able to approve up to four files at the same time in his Power Automate approval task, is there a way to make the number of attachments optional?”
To make the approval process in Power Automate as user friendly as possible, you might want to include attachments in the task. It can be the item attachments or multiple documents from a library, but you can’t predict how many files it’ll be. And that can be a problem in the ‘Start and wait for an approval’ action. If you define more attachments than you have, the flow will end with ‘InvalidAttachmentName’ error. If you define less attachments than you have, some documents will be missing in the task.
The solution is to build a dynamic array with the attachments as a variable and use it in the action.
Adding the attachments
First step you need to do is to initialize the array variable.
The next step is to get all the files. It can be ‘Get attachments’ action, ‘Get files’ action, or a list of files you’ll build by yourself. To keep the number of files optional you must be able to loop (‘Apply to each’) through them.
Loop through all the attachments, get their content, and append them into the variable with the ‘Append to array variable’ action. The code below shows you the format, just don’t forget to replace the <placeholders> with your dynamic content.
"content": <AttachmentContent or FileContent>
Warning: make sure you don’t add any character nor white space after the <AttachmentContent or FileContent> dynamic content. Otherwise you’ll end with ‘AttachmentContentNotValidBase64String’ error.
In the example below, you’ll take all attachments from a SharePoint item and append them into the variable.
Last step is to send the actual approval task, with our array variable as attachments.
As a result, the approver will receive an approval task with all the attachments. Not only in the email, but in the task in the Power Automate application as well.
While I generally don’t recommend sending files as email attachments, I’d make an exception in the approval task. For the approval process it’s much easier if the approvers have all the information at the same place. The information needed for approval in the task, the final approval history directly in the list/library.
Unless they need to do some update in the file itself, then a link to the file locations is the only way.