Assign approval task with multiple (0 – n) attachments in Power Automate

“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.

Approval task input attachment detail

The solution is to build a dynamic array with the attachments as a variable and use it in the action.

Approval task input attachments array

Adding the attachments

First step you need to do is to initialize the array variable.

Initialize 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.

{
  "Name": <DisplayName>,
  "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.

Store item attachments into array

Last step is to send the actual approval task, with our array variable as attachments.

Assign task with array of 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.

Approval task with multiple attachments

Summary

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.


Do you struggle with the various expressions, conditions, filters, or HTTP requests available in Power Automate?

I send one email per week with a summary of the new solutions, designed to help even non IT people to automate some of their repetitive tasks.

All subscribers have also access to a special content like a SharePoint Filter Query cheat sheet.

Zero spam, unsubscribe anytime.

Add a Comment

Your email address will not be published. Required fields are marked *