Many people don’t know this, but you can add attachments to a SharePoint list row. It’s convenient and much better than having a folder with files. And with SharePoint’s “Add attachment” action, we can automate the whole process.
A previous note before we continue in case you don’t know how to display the attachments in your list. To do it, in any list, go to “Add column”:
You may need to scroll down to find “attachments”:
After selecting it, don’t forget to press “apply”.
A new column will show up in your list with the attachments.
Now that we know where to find it in SharePoint let’s see how to automate the process.
Where to find it?
You can find the “add attachment” action in the SharePoint section. Select “Standard”:
You may need to expand to find SharePoint.
Select SharePoint.
Find and select the “add attachment” action:
Here’s what it looks like:
Now that we know how to find it let’s understand how to use it.
Usage
The action does one thing, but it does it well. Get a file and add it to the SharePoint site’s list row.
Let’s create a sample list to test our process.
And a Flow that can insert the data. We’ll do the following:
- Create a new item in the list.
- Get the file contents using OneDrive’s “Get File content” action.
- Add the file to the newly created item.
Here’s what it looks like:
Let’s run it and see what we get. Here’s the SharePoint list result:
We have an attachment, and if we press the row, we’ll get the results:
Please note that you don’t need to keep the same file name in action. You can define any other name, and it will be created with that name on SharePoint. Here’s an example:
And we get:
Limitations
You should limit concurrency while using the “add attachment” action. For example, if you’re adding multiple files at the same time, do it sequentially; otherwise, you’ll have Flows that don’t stop, like this:
But if you do it consecutively, you’ll be able to run it instantly.
Another limitation is that the names need to be unique.
If you try to insert a value with the same name, you’ll get:
The specified name is already in use.
The document or folder name was not changed. To change the name to a different value, close this dialog and edit the properties of the document or folder.
clientRequestId: c62f3b1f-07ea-467b-bb9a-406d73234120
serviceRequestId: 26681fa0-20e5-3000-d4f1-1971357fae71
This will happen even if the files are completely different. As long as the name is other, then you’ll get this exception.
A hidden issue
Sometimes you may get the following error “page” instead of an error message.
<!DOCTYPE html>
<html>
<head>
<title>The resource cannot be found.</title>
<meta name="viewport" content="width=device-width" />
<style>
body {font-family:"Verdana";font-weight:normal;font-size: .7em;color:black;}
p {font-family:"Verdana";font-weight:normal;color:black;margin-top: -5px}
b {font-family:"Verdana";font-weight:bold;color:black;margin-top: -5px}
H1 { font-family:"Verdana";font-weight:normal;font-size:18pt;color:red }
H2 { font-family:"Verdana";font-weight:normal;font-size:14pt;color:maroon }
pre {font-family:"Consolas","Lucida Console",Monospace;font-size:11pt;margin:0;padding:0.5em;line-height:14pt}
.marker {font-weight: bold; color: black;text-decoration: none;}
.version {color: gray;}
.error {margin-bottom: 10px;}
.expandable { text-decoration:underline; font-weight:bold; color:navy; cursor:pointer; }
@media screen and (max-width: 639px) {
pre { width: 440px; overflow: auto; white-space: pre-wrap; word-wrap: break-word; }
}
@media screen and (max-width: 479px) {
pre { width: 280px; }
}
</style>
</head>
<body bgcolor="white">
<span><H1>Server Error in '/' Application.<hr width=100% size=1 color=silver></H1>
<h2> <i>The resource cannot be found.</i> </h2></span>
<font face="Arial, Helvetica, Geneva, SunSans-Regular, sans-serif ">
<b> Description: </b>HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.
<br><br>
<b> Requested URL: </b>/sites/<redacted>/_api/web/lists/GetByTitle('Recepció<redacted> / <redacted>')/Items(7)/AttachmentFiles/AddUsingPath(decodedUrl=@f)<br><br>
</font>
</body>
</html>
clientRequestId: f7a73f84-3a71-4e60-8cda-ef1258a8bcc2
Here’s what it looks like in Power Automate.
And this is a “normal” exception:
So what’s happening here? We’re getting the values from the trigger.
The issue is not the trigger but the name of the list. The problem is not the trigger but what happens when you call the “add attachment”. When the list name is provided dynamically, the connector makes an HTTP request like this:
SharePoint needs to do this call to find the list’s ID so that it can perform the action, but the _api/web/lists/getbytitle
has an issue that limits the forward slash. So the action “panics” and returns an exception instead of an error. But, of course, this won’t happen if you pick the list from the dropdown since SharePoint doesn’t need to try to find the list.
I tried encoding the whole string, only the forward-slash, and it didn’t work. The only solution I found was to pick it from the dropdown, and it all started working. So if you have lists with forward-slash, you know that you always need to hard-code the list in the “add attachment” action.
I believe this is a bug, but it’s tricky to understand, but I wanted for you to understand it in case you’re spending time (in my case, a few hours) trying to figure it out.
Recommendations
Here are some things to keep in mind.
Avoid using dynamic values, especially the list name
Although you can provide the dynamic value for the SharePoint site and list name, please avoid doing it. There are some limitations in the API that Power Automate uses to access SharePoint so that you may have strange issues (like described above).
Name it correctly
The name is super important since “add attachment” doesn’t tell much. Always build the word so that other people can understand what you are using without opening the action and checking the details.
Always add a comment.
Adding a comment will also help avoid mistakes. Indicate the file we’re adding, for example, to what site and list and the point. But, again, it’s essential to enable faster debugging when something goes wrong.
Always deal with errors.
Have your Flow fail graciously and notify someone that something failed. It’s horrible to have failing Flows in Power Automate since they may go unlooked-for a while or generate even worse errors. I have a template, and a template that you can use that will help you make your Flow resistant to issues. You can check all details here.
Back to the Power Automate Action Reference.
Photo by Jen Theodore on Unsplash
Hi Manuel,
I am actually trying to put items from the document library into the attachment column in my Sharepoint list. For example, a file from a client that was uploaded to onedrive will first up copied a sharepoint folder. then is to be added to the client’s row in my sharepoint list based on if the attachment file contains “client name” then it is automatically added to that row.
i tried to reverse engineer this based off of your post. but i can’t the part to work that cross references the client name in the list with the name of the file. i use the get items action with filter expression: contains(body(‘Get_items’)?[‘value’], ‘First Name’)
and then it fails with: Flow save failed with code ‘InvalidTemplate’ and message ‘The template validation failed: ‘The ‘inputs’ property of template action ‘Get_items’ at line ‘1’ and column ‘2221’ is not valid. The action cannot reference itself.’.’.
any change you can point me in the right direction?