Add 0-n attachments from SharePoint to a Planner task in Power Automate
Posted On April 25, 2021
“I have a Power Automate flow set up to create tasks in Planner as well as update the task details, but how do I add also attachments?”
Some Planner tasks need more information than just the task itself and a checklist. It can be a task created from a SharePoint item, task from a file in a SharePoint library, or a repeated task created from a SharePoint template. In all these situation Power Automate can add also attachments to the Planner task during creation. But how can you do it with various (0-n) number of attachments?
Single attachment (flow triggered on a file)
First things first, if your flow is triggered on a file, you can add the file directly. Use the ‘File name with extension’ as the ‘Reference Alias’ and ‘Link to item’ as the ‘References Resource link’. The ‘References Type of the reference’ can stay empty.
Since the flow will trigger on a file, the file must exist. And since you can’t attach another file to a file, there’ll be always just a single file = you can use the detailed input.
But if your flow is not triggered on a file, or if you want to attach few more files from other sources, you’ll need to store them in an array.
The approach is similar to adding multiple attachments to an email or to an approval task. You should build an array with the attachments and then use the array in the ‘Update task details’ action. If it’s an array, it doesn’t matter how many attachments it has. Empty array will add 0 attachments, array with N items will add N attachments.
Firstly, initialize an array variable, the one that will contain all the attachments.
Secondly, get all the files you’d like to add to the Planner task. You can use ‘Get attachments’ to get the file ‘DisplayName’ and ‘AbsoluteUri’ from item attachments, and append them to the array:
Or ‘Get files (properties only)’ to get the file ‘File name with extension’ and ‘Link to item’ from a document library, and append them to the array.
In all situations, the format used in the ‘Append to array variable’ must be as below:
Note: <…> indicates a placeholder, replace it including the < and >.
Once you’ve got all the files in an array (after the ‘Apply to each’ processing the files) you can add them to the Planner task.
When you add attachment to a Planner task with Power Automate, you don’t add the whole file (unlike an email or an approval task). You add just a link to the file – a file stored in SharePoint in this case. As long as the file is in SharePoint, you can reference it from the task. It can be item attachments, it can be files from a document library, or you could even create an attachments template similar to the task checklists.