2 Ways to Add Attachments to a Planner Task in Power Automate

Do you need to attach a file to your Planner task in Power Automate?

Suppose you want to create Planner tasks with attachments as part of a flow.

Power Automate can help you automate your Planner task creation, but it’s not very obvious how to attach files to your tasks. Adding multiple attachments is even more tricky.

This post is going to show you how to attach single or multiple files to your task in your flow.

Where are Planner Task Attachments Stored?

Each Plan in Planner is associated with a SharePoint site. Any files you attach to a task in the plan will be stored in the associated SharePoint site.

You can easily find this site and the file storage location from Planner.

Go to the Plan and click on the Ellipsis icon in the top menu bar and select the Files option.

This will open the SharePoint site at the location where all attachments are stored for the plan.

This post will assume the file or folder of files to attach is already saved in this location on SharePoint.

Add a Single Attachment to a Planner Task

Adding a single file from the SharePoint folder is the easiest option.

This involves getting the file ID based on the file path and then using the ID to get the sharing link. The sharing link is then added to your Planner task.

Here are the steps to add a given file to your Planner task.

  1. Add the Get file metadata using path action from the SharePoint connector.
  2. Select the Site Address for the SharePoint site associated with your Plan.
  3. Select the File Path of the file to attach. This should be in the Shared Documents library. Note, this is the same thing as the Documents library.
  4. Add the Create sharing link for a file or folder action from the SharePoint connector.
  5. Select the same Site Address for your Plan.
  6. Select the Documents option for the Library Name.
  7. Add the ItemId dynamic content from the Get file metadata using path action.
  8. Select the View and edit option for the Link Type. This ensures Plan users will be able to use the file normally.
  9. Select the People in your organization option for the Link Scope. This ensures everyone in your organization can use the file.

This is all you need to add a single file to a task.

Now you can create and update a task with the attachment.

  1. Add the Create a task action from the Planner connector to your flow and will in the required details. This is an optional step and is only needed if you are creating the task within the flow. If you already have a task, this can be selected in the Update task details action.
  2. Add the Update task details action from the Planner connector to your flow.
  3. Add the Id dynamic content to the Task Id field from the Create a task action or select the Task Id from an existing task.
  4. Add the DisplayName dynamic content from the Create sharing link for a file or folder action to the References Alias field. This will show the file name for the attachment in the task.
  5. Add the Sharing Link dynamic content from the Create sharing link for a file or folder action to the References Resource link field. This will link the attachment to the task.

When the flow runs, it will create the sharing link and add it to the task!

Add Multiple Attachments to a Planner Task

The process of adding more than one file, such as all the files in a given folder is more complex.

It will require creating an array variable and adding all the sharing links to the array. This requires looping through all the files in the folder and appending the file details to the array.

Here are the steps needed to add all files in a folder to your Planner task.

  1. Add the Initialize variable action to your flow. This is the array variable that will hold the names and sharing links to each file in the folder.
  2. Give your variable a name such as arrAttachments. This is how you will refer to it later on in the flow.
  3. Select the Array option for the Type of variable.
  4. Leave the Value input blank so you create an empty array.
  5. Add the Get files (properties only) action from the SharePoint connector to your flow. This will get you the ID of each file in a selected folder and the ID will later be used to get the share link for the file.
  6. Select the Site Address of the SharePoint site associated with the Plan.
  7. Select the Documents library for the Library Name.
  8. Select the folder in the Limit Entries to Folder input within the Documents library that contains all the files you want to attach.
  9. Choose either Yes or No for the Include Nested Items option. Choosing Yes will include all files in all the subfolders within the main selected folder. Choosing No will limit the files returned to files in the top-level folder only.

Now you will be able to loop through the output of the Get files action and get the sharing link for each file.

  1. Add the Create sharing link for a file or folder action from the SharePoint connector.
  2. Select the Site Address associated with your Plan.
  3. Select the Documents library as the Library Name.
  4. Add the ID dynamic content to the Item Id field. This will automatically add the Create sharing link for a file or folder action into an Apply to each action. This allows the action to loop through each file ID in the folder from step 8.
  5. Select View and edit for the Link Type. This will allow the file to be viewed and edited when opened from your Planner task.
  6. Select the People in your organization option to allow anyone in your tenant to use the file from the link.

This will get you the name and sharing link of each file and these can be appended to the arrAttachments array.

  1. Add the Append to array variable action to the flow inside the Apply to each action.
  2. Select the arrAttachements variable for the Name input. This is the variable that was previously initialized in the flow.
{
  "alias": @{items('Apply_to_each')?['{Name}']},
  "resourceLink": @{outputs('Create_sharing_link_for_a_file_or_folder')?['body/link/webUrl']}
}
  1. Add the above code to the Value input.

This is a record with two key-value pairs. The alias field contains the Name dynamic content from the Create sharing link for a file or folder action and the resourceLink field contains the Sharing Link dynamic content from the Create sharing link for a file or folder.

This record template can be seen when you click on the Switch to input entire array button in the Update task details action.

One record will be added to the array for each file in the folder and this array is used as the input in the Update task details action of the Planner connector.

  1. Add the Create a task action from the Planner connector if you are also creating the task within the flow.
  2. Add the Update task details action from the Planner connector to your flow.
  3. Add the Id dynamic content from the Create a task action to the Task Id input.
  4. Click on the Switch to input entire array button. This allows you to add the attachments as an array input.
  1. Add the arrAttachments dynamic content to the References input.

Now when the flow runs it adds all the files from your folder!

Conclusions

Having files attached to your Planner tasks is a convenient way to keep all associated work with the task.

It is possible to add a single file or all files in a folder to a task in Power Automate, but it is tricky.

With these methods, you will be able to add any attachments from SharePoint.

Have you ever needed to add files to your tasks in a flow? How did you get this done? Let me know in the comments below!

About the Author

John MacDougall

John MacDougall

John is a Microsoft MVP and freelance consultant and trainer specializing in Excel, Power BI, Power Automate, Power Apps and SharePoint. You can find other interesting articles from John on his blog or YouTube channel.

Related Articles

Comments

2 Comments

  1. Sérgio Ferreira

    Hi,
    I made a flow to generate a email file each time an email arrives and add it to a new task.
    The problem is tha it is creating 2 tasks instead of one.
    I read somewhere that a array can be used but i don´t know how.
    Can you help me?
    Thanks

Get the Latest Tech Tips

Write For Us

Are you a tech enthusiast with a talent for writing great content? Come write for us!

Follow Us

Follow us on social media to stay up to date with the latest in tech!