Power Automate
How to add dynamic attachments in Send Email/Approval Action

How to add dynamic attachments in Send Email/Approval Action

In some scenarios, we may need to add attachments while sending emails to businesses, Some times the attachment files will be dynamic and it will be changed based on users or scenarios.

We may get the files from SharePoint, Onedrive, Azure, or any HTTP request, In all cases we can follow the below steps. In this example, we get the files from SharePoint.

Declare an array variable to hold the file content in JSON format, get the required file reference from SharePoint.

Get file reference from the library

Pass the output to Apply to each, get the file content by passing the current record identifier.

Get file content

Apply to Each => Append the JSON to an array variable

Append to an array variable

Outside apply to each => Pass the array variable to send email action.

Approval

This works perfectly well for Email action, But if the attachments need to be added in an “Approval” action. The JSON for the array has to be formatted slightly different like below.

JSON Format
{
  "Name": "@{items('Apply_to_each')?['DisplayName']}",
  "content": {
    "$content-type": "@{body('Get_attachment_content')['$content-type']}",
    "$content": "@{body('Get_attachment_content')['$content']}"
  }
}

Please post your queries in the comment section. Happy Building šŸ™‚

0

Leave a Reply

%d bloggers like this: