“I use Power Automate to synchronise two SharePoint lists, but I don’t know how to update the item attachment, what’s the best approach?”
Very often when you synchronise two SP lists, it’s enough to synchronise the columns. With every change in one of the columns you’ll do the same change in the second list. But what about item attachments? If users update the attachment, how can you update it also in the second item?
Where is the attachment stored
If you check the output of the ‘Get attachments’ action, you’ll see the location of the attachment. All the attachments are stored directly in the list in hidden folders. It’s the folder /Attachments/, followed by the /item id/ and the actual /file name/.
It’s a bit different from other files as even though you’ve got the url, you can’t open it in browser. But you can process the attachments as any other file, if you know its identifier.
Don’t try to update the attachment
While it might be tempting to try to update the attachment, similar to updating any other file in SharePoint, I don’t think it’s worth it. Unlike the updates in columns, it’s not possible to recognise if there was any change in the attachments. Flow to update the attachments would have to check if given attachment exists, and create or update it later. It would have to process all of them.
Replace the attachment
Since all the attachments are stored in a hidden folder in the SharePoint list, they don’t support the standard document features. They don’t move to the recycle bin after deletion, nor are they keeping versions. Attachments either exist or they don’t. Therefore, if you decide to save some work, you can just delete all the existing attachments and upload them again. You won’t lose any functionality nor save API calls.
You also don’t have to check if the attachment exists, or connect the attachments if there’s more of them. Just do a full cleanup and re-upload.
Summary
As you can see, the best approach to update item attachment in Power Automate is to actually replace them. No checking if the attachment exists nor connecting with an existing one. A simple upload and delete will do the trick.
Thanks for the tips, this is quite helpful. Is there an option to update the attachment field. Assuming I have a document that has been updated (approved) in a document library, but the list item attachment column of another SharePoint list already holds a picture file and I just want to amend the list item attachment to include the updated updated file if a condition is met?
Hello George,
if it’s only about adding a new attachment to a SP item then you can do that, just get the file content and add it as a new attachment to the item, the existing attachments will stay intact.
This is great if you know the list. However, if the list itself is dynamic, how can you add an attachment? I’m already creating the list item through an HTTP call, but can’t figure out how to add the attachment to the new list item.
Got it! I used “Add Attachment” and was able to get the ID of the new list item from the previous action to create the item. Thankfully, the list always has the same name, the site is just different.
Hello!
Thanks for this post, could you please show how to upload attachments to existing sharepoint list items. In order to match correct pdf to correct item this should be done with the same name on the list item and attachment.
I have for example 50 pdf files all with a certain unique name. I have also 50 sharepoint list items with the same names. Now I want to update the sharepoint list items with the corresponding pdfs as attachments to the list items in one go.
I really appreciate if you could showcase this example.
BR
Melissa
Hello Melissa,
list all the items in the list, for each item find the corresponding file using the file name: https://tomriha.com/power-automate-to-filter-file-in-sharepoint-by-file-name/, and update it. Get items -> Apply to each (output from Get items) -> Get files (properties only) with the filter by file name -> Add file attachment
Hi, Tom is there a more detailed way of these steps? I’m encountering the same problem where when a new file is created from a Plumsail FORM, the PDF needs to be added as an attachment to the items in a SP list. the common name of both the SP list item and file name I’m attaching is the Company Name so I can use this to find which Item in the SP list it needs to be attached to. The company names are unique values so no repetition will happen.
ex: List Item Name= XYZ company then Filename=XYZ Company.pdf.