
Last time out we looked at how to add an unknown number of email attachments to a Planner task. We accomplished this by looping through all of the attachments, adding them to an array, and then adding the array to the Planner task.
What if we want to do the same thing for an Approval?
The process is very similar but with one key difference: Planner requires you to store the file and then attach a link, whereas an Approval allows you to attach an actual file.
This means that whilst the general process is the same - 1) loop through the attachments, 2) add them to an array, 3) add the array to the Approval - the specifics are slightly different.
For Planner we used a Create file step and then appended the link from that step to the array. For Approvals we're going to do an extra step to Get file content so we can attach that content to the Approval instead:
The array is in JSON format as usual, and for Approvals this is the syntax:
{
"name": "[file name]"
"content": "[file content]"
}
We will use the Name of the attachment for the name and the Body of the file from the Get file content step for the content in our Append step:
Every loop of the Apply to each loop will add an additional attachment to the array.
After the loop has finished, we create the Approval and then we click the Switch to input entire array option and use the Approval Attachments variable:
Now your Approval will have multiple attachments, regardless of whether the email has 1, 3, 5, or more attachments.
Unlike the Planner solution, the files created by the Create a file step in the Apply to each loop are not needed once you've you've attached them to the Approval. This means you can add in a step to delete the folder of attachments after you've created the Approval if you want.
(Technically you could add a delete step in the loop so that the file is deleted as soon as it has been added to the array but this makes debugging more difficult if there is a problem so I wouldn't recommend this.)
No comments:
Post a Comment
Note: only a member of this blog may post a comment.