Forum Discussion
KristaJ
Microsoft
Jul 31, 2020How to get an attachment provided via FORM added to Sharepoint List
I've created a FORM that has a number of questions, including the option for a user to add an attachment. Then via FLOW all answers to the questions are getting added to a Sharepoint List. Everything is working great except the attachments are not getting stored.
1. What are the steps to enable the attachment a user provides in the FORM to get added to a Sharepoint list via FLOW?
2. How do I add an Attachment column in Sharepoint List (maybe this is part of my issue)
Any other thoughts? Thanks for the help.
- craigsilvercfCopper Contributor
Thanks for the post. I am successfully checking for an attachment because when I don't supply one, the list receives the result. However, when I supply an attachment, my Parse JSON errors with:
"JSON.parse: bad escaped character at line 1 column 1834 of the JSON data"
I copy/pasted the JSON into Notepad++ and it doesn't seem to have anything funky in it, just spaces for the indentation and CR/LF's at the end of each line. Character 1834 looks pretty benign. See below.
Any advice?
Thanks. - RobElliottSilver Contributor
KristaJ to answer your question 2 first, you need to edit the view of your list and make sure the Attachments column is displayed:
The actions in the flow to get the uploaded file and attach it to the list item are a bit complicated but it works very well. After your trigger and the Get response details action add a Parse JSON. In the Content field select from the dynamic content box the Forms question that had the file upload (in my case it was "If you have a file or image with more information please upload it here").
Then in the Schema field paste in the following JSON code:
{ "type": "array", "items": { "type": "object", "properties": { "name": { "type": "string" }, "link": { "type": "string" }, "id": { "type": "string" }, "type": {}, "size": { "type": "integer" }, "referenceId": { "type": "string" }, "driveId": { "type": "string" }, "status": { "type": "integer" }, "uploadSessionUrl": {} }, "required": [ "name", "link", "id", "type", "size", "referenceId", "driveId", "status", "uploadSessionUrl" ] } }
Next, because Forms saves the uploaded file to the OneDrive of the flow's creator you need to you need to add a OneDrive action to get the file content. You select the path up to and including a file that has been uploaded, but in the file path field delete the file and add the Expression
first(body('Parse_JSON'))?['name']When creating the list item you can't add the attachment at the same time. I always introduce a short delay - 10 seconds is fine - so that the create item action has time to complete before doing anything else on the list:
Next, add an Apply to each and in the first field select Bodyfrom the Parse JSON section of the dynamic content box. Then add a SharePoint Add attachment action and select the site and list. In the ID field select ID from the Create item section of the dynamic content. In the File name field select Name from the Parse JSON section of the dynamic content. For the File content field select File content from the Get file content using path section of the dynamic content.Rob
Los Gallardos
Microsoft Power Automate Community Super User.
If I've answered your question or solved your problem, please mark this question as answered. This helps others who have the same question find a solution quickly via the forum search. If you liked my response, please consider giving it a thumbs up. Thanks.- JRBZA69Copper Contributor
RobElliott Thanks, that instruction worked like a charm for a single file. When I upload multiple files in my Forms response and run the flow to put them into a SharePoint list, I do get two separate file names (one per file uploaded and they are correct.) The issue is that the same document is saved under both separate file names, as if one document overwrote the other. Again, 2 file names, same actual file.
I have tried a few options - adding a second Apply to Each, moving steps around, etc. Nothing works. Suggestions anyone?
- amiranda79Copper Contributor
RobElliottI would just like to say thank you so much for posting this. I have been trying and trying to get the attachments to attach in SharePoint for weeks now, tried many other ways given by other users and no success, but yours works beautifully! thank you so much!
- neeesz78Copper Contributor
- AnaBurtilaCopper Contributor
RobElliott Thank you for sharing the flow. I tested it and I get the following error:
{"status": 401,"message": "A potentially dangerous Request.Path value was detected from the client (?).","source": "api.connectorp.svc.ms"}Any ideas on how to solve this?Thanks!