Jul 31 2020
10:39 AM
- last edited on
Aug 03 2023
10:35 PM
by
TechCommunityAP
Jul 31 2020
10:39 AM
- last edited on
Aug 03 2023
10:35 PM
by
TechCommunityAP
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.
Aug 02 2020 02:25 AM - edited Aug 02 2020 02:30 AM
@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
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.
You'll probably have other actions as I do, but that's all the actions you need to add the file uploaded from the form into the SharePoint list. So, in live use I have uploaded an image in the form:
The flow runs, creates the item in the SharePoint list then adds the attachment to it. In the view it will show there is an attachment. When I edit the form (in this case it's a PowerApps customised form) the attachment name is shown and clicking it will download it for the user.
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.
May 18 2021 01:55 PM
@RobElliott Thank you for the how-to. I follow your guide as exactly as I can tell however, I am running into a problem. When there is no attachment the flow fails.
May 18 2021 02:01 PM
May 27 2021 01:18 PM
@jmillar99 are you only getting this error when there is no attachment? If so, try adding condition so if there is no attachment it skips this step.
1. Check for attachment = True
2. If True do this
3. If False do that
Perhaps that'll help
May 27 2021 07:55 PM
May 28 2021 03:55 AM - edited May 28 2021 03:59 AM
@kitafocus @KristaJ @jmillar99 make sure that in the Get file content using path action that in the settings you have set the Configure run after so that the is successful and has failed checkboxes are checked. And do the same with the action that follows it, in my case it's a Get user profile (V2). The flow will then run successfully even if no document has been uploaded. My apologies, I missed this rather crucial step out of my earlier post.
Rob
Los Gallardos
Microsoft Power Automate Community Super User
Jun 15 2021 03:42 PM
@RobElliott My flow works correctly but the attachment in the List is decoded incorrectly. When I download it, it can't be opened properly. Not sure what is going on. Any troubleshooting ideas?
Jun 16 2021 01:33 AM
@RachelDaines it's because it's not getting the extension. So in the add attachment action, in the file name field try selecting file name with extension from the dynamic content box. Or if they are all going to be the same extension, e.g. docx, then you can type .docx atthe end of the field.
Rob
Los Gallardos
Microsoft Power Automate Community Super User
Jul 29 2021 11:39 AM
@RobElliott I'm running into an issue where File Content isn't an option in my Dynamic Content. Any suggestions?
Sep 27 2021 04:25 PM
@RobElliott Hi Robert. Thank you for sharing your wealth of knowledge. Would you be able to provide a screenshot of your entire flow without the detail for each step? I just want to see how your steps are laid out in its entirety. Thank you.
Sep 28 2021 05:16 AM
@kabap5 the full steps in the flow are shown below, and so far it has run 6725 times and works both if a file has been uploaded in the form but also if it hasn't:
Rob
Los Gallardos
Microsoft Power Automate Community Super User
Oct 29 2021 03:19 AM
Hello@RobElliott ,
I am still having that issue after checking both the boxes as well for success and fail.
Oct 29 2021 03:21 AM
Nov 16 2021 02:23 PM - edited Nov 16 2021 02:38 PM
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.
Sep 05 2022 11:42 PM
@RobElliottI couldn't solve the getting file content from the OneDrive folder. Can you please help me with what the problem is?
Aug 21 2023 12:59 AM
@RobElliott Thank you for sharing the flow. I tested it and I get the following error:
Sep 12 2023 06:39 PM
@erentekin Did you figure out how to fix this error? I'm getting the same one.
Sep 13 2023 01:29 AM
@Jen_125 No, unfortunately I did not manage to fix this yet.
Jan 25 2024 07:07 AM
@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!