Forum Discussion
How do i add attachments from Microsoft Forms onto Sharepoint List
- Jul 04, 2021Don't use a template to build this flow which will put in that first apply to each which is not needed and usually causes problems. Build it from new going straight from When a new response is submitted to get response details.
Sur76 So what did you do in the end, exactly? In my Get Response Details it never shows anything about the attachement from the Form?
GBeulen no it won't, the steps you need to add a file uploaded to a Microsoft Forms form to an attachment in a SharePoint list are as shown below.
Your trigger is the Forms "when a new reponse is submitted". The first action as always is the Forms "get response details":
You now need to add a "Parse JSON action". In the content field select the question from your form where you asked the user to upload the file.
The schema field will work with the following:
{
"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"
]
}
}
The file is always saved to your OneDrive in the
first(body('Parse_JSON'))?['name']
Next, create an item in your SharePoint list:
Next, add an "apply to each" action and in the first field select Body from the Parse JSON section of the dynamic content box.
Finally, inside the apply to each add a SharePoint "add attachment" action. 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 box. In 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
- keenan_meadowsAug 20, 2024Copper Contributor
How do I find these settings? I understand this answer is a few years old, but I cannot duplicate the instructions here because I am not able to find where to put the trigger in the forms.
Thanks.
- navyjax2Sep 03, 2024Copper Contributor
keenan_meadows It's not about triggers... it's about just searching for the events.
When you do "New Step" in the workflow, you'll keep your category to "All" and look for "Parse JSON", which is in Data Operations.Next step. Search for "Get file content using path", select "One Drive for Business" after getting results to refine what you are looking for. Be careful to get the one that says "...using path", not just "Get file content".
Next step. You shouldn't even need to search for "Apply to each". It should be in the Actions as soon as you create a new step.
Inside the "Apply to each", select "Add an action". Search for "Add attachment". If the SharePoint one doesn't appear, select the SharePoint icon and then look for it. It should be the first one.
- BbhuvaMay 13, 2024Copper Contributor
Could you assist me in resolving the issue with my flow? I have a flow set up where a Microsoft Form submission creates a list in Microsoft List with attachments. While I'm able to see the attachments in the Microsoft List, I encounter an error when attempting to open them.
Thanks in advance.
Bhavesh
- navyjax2Sep 03, 2024Copper ContributorYou might want to check your file path. In the original example he gave, he didn't have "/Shared Documents/Apps/Microsoft Forms", but it just started with "/Apps/Microsoft Forms". Maybe that could be your problem?
- navyjax2Sep 06, 2024Copper Contributor
So I was doing all of this myself and ran into several issues that eventually I figured out and resolved, so I want to give everyone on this thread and those that may arrive here in the future this heads up. I'll provide my way of doing it and pitfalls of doing it the way that was originally suggested:
1. Parse JSON - this can be used exactly as was originally suggested, however it has a limited relevance/usage capability, as I will explain later.
How it is set up is that you will have the form response object for the question you asked on your form that told them to "Upload Documentation", is what I named mine and how I will refer to that going forward. The schema provided was correct, though perhaps had some unnecessary attributes and lacking in others. The key ones are size, name, link, and id.
{ "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" ] } }
Where the ability to use this is advantageous is because "link" in the output has the full path to where MS Forms is storing your files. Where it breaks down is that most objects you would implement to get that file require the relative path, not the absolute one, so you would have to do string manipulation and/or concatenation with the name attribute to form a URL, and this does not seem to work in any of the "Get file content using path" methods. So I went on to do Step 2.
2. Add a SharePoint "List Folder" object. I found that the URL in the "Parse JSON" "link" property went to our Teams site, but this will be wherever your MS Forms are being hosted and could vary by your setup/institution. If you add your MS Form to a group, it would likely appear on the group's Teams site, so if you intend to make your form available to a group to edit, do this first, as it will affect both the path where attachments are stored, and the Form ID your workflow uses for getting form responses. For us, the path where attachments were stored was baseURL/teams/groupname (as opposed to baseURL/sites/somesitename that others might get if MS Forms was set up to communicate with another SharePoint site).
Files were being saved to the relative path of /Shared Documents/Apps/Microsoft Forms/FormName/QuestionName, so this became the File Identifier. It does not need to be drilled down to a specific file. The file picker can also aid with drilling down to the path. You do not need to concatenate in a file name, here - just the folder will do.
3. Apply to each. You will need to iterate the "List Folder" object's output, and so the "output from previous steps" is the body of the List Folder: body('List_folder')
This will allow access to the properties of each individual file:
- Size: in KB
- Path: relative path to the file, including its name, no URI-encoding (for use in "Get file content using path" methods)
- Name: file name only
- ID: relative path to the file, including its name, URI-encoded (for use in "Delete file" method)
4. Condition: Is the File Size greater than zero --
item()?['Size'] greater than 0This is needed because occasionally a temporary file of 0 KB is created and left behind, and if the loop hits that file and the "Get file content using path" method in the next step attempts to grab it, it will not be able to and the workflow will go on forever, forever attempting to retrieve a 0 KB file.
Note: All remaining steps must be placed in the "Yes" branch of this condition.
5. Use SharePoint's "Get file content using path" method.
The example earlier in this thread was to use the OneDrive "Get file content using path" method by concatenating the "Parse JSON" "name" attribute with a relative URL that is manually typed in, using first(body('Parse_JSON')). There are multiple issues with this:
- If you aren't looping through the "Parse JSON" object, you will only ever get the first file name available. This is fine if you are only getting 1 file, but it will not work for a real-world scenario where you allow multiple files to be attached.
- Even if you looped through the "Parse JSON" and concatenated item()?['name'] to the end of a manually typed relative URL, it would not accept it.
Here are the attempts, if you were using "Parse JSON":
concat('%2FShared%20Documents%2FApps%2FMicrosoft%20Forms%2FMY20AWESOME%20FORM%2FUpload%20Documentation%2F',item()?['name']) concat('%2FApps%2FMicrosoft%20Forms%2FMY20AWESOME%20FORM%2FUpload%20Documentation%2F',item()?['name']) concat('/Shared Documents/Apps/Microsoft Forms/MY AWESOME FORM/Upload Documentation/',item()?['name']) concat('/Apps/Microsoft Forms/MY AWESOME FORM/Upload Documentation/',item()?['name'])
(It would be item()?['Name'] using "List Folder".)
I saw in the example on this thread that it started with /Apps, but my URL starts with /Shared Documents. I thought this was just a difference in setup, but I since was told by a Microsoft person that omitting /Shared Documents might have actually been the way to go. I tried this, however, and got no joy.
The above attempts will give you the error "The resource could not be found." using the OneDrive "Get file content using path" method and will give you either "File not found" or "Route did not match" when using SharePoint's "Get file content using path" method. You can't "concat" your way to a happy ending - at least, using the object method directly, as an expression. And even if you just type the path and then add in the item()?['name'] as an expression at the end, it did not work for me. Perhaps if it was put into a Compose or variable ahead of the object, maybe then it might work, either with or without the /Shared Documents part. But after having enough of this, I found that there's something even easier.
When you have the "List folder" method, you can access item()?['Path'] within the "Apply to each". This is the non-URI-encoded relative path to the file and it works flawlessly. Just put that, and ONLY that for the File Path: item()?['Path']
6. Use SharePoint's "Add attachment" method.
Use the Site address and List Name where the list resides - this is not likely to be the same as your site containing the attachments, so don't go in with blinders and automatically put in the wrong site, or when you go to look for your list, it won't be there. Pick the right site for where your list is where you are creating items.
The "Id" is the ID of the list item from your "Create item" you did earlier. Get its output from the dynamic content.
File Name is item()?['Name'] -- this is the file name property from the item in the "List Folder" method that we are looping through.
File Content is the "File Content" from the output of the "Get file content using path" method, accessible in the dynamic content. It will appear as "Body" in the textbox when selected.7. Use SharePoint's "Delete file" method.
This is to remove any files that were uploaded at the previous location and prevent the next form run from causing your workflow to grab files from previous runs and add them to new list items - we do not want that. Instead, clearing out the files is a necessity so we only grab what was uploaded and is for that particular item.
Site address: the same URL from Step 5, where MS Forms attachments are being uploaded
File identifier: item()?['ID']The "ID" for the "List Folder" object is the URI-encoded path, including file name, to the file. It is not the same as the ID in "Parse JSON", which is a useless alphanumeric string that you cannot even use to grab the file with when doing methods that use an ID to get the object.
This "ID", in the "List Folder" object, is what this method needs in order to latch onto the file - much the same way as item()?['Path'] was used in the "Get file content using path" method earlier, in Step 5.
This should give everyone what they need in order to solve their concatenation and parsing issues and avoid the pitfalls of using "Parse JSON" with the OneDrive and SP methods in ways these methods will not accept, while you can give it the "Path" and "ID" in the methods above from "List Folder" and it will take them just fine.
- dbohanickJan 04, 2024Copper Contributor
This was great, but what if you want to have the option to include or not include the attachment from the Form to List. I mention this because when I used your workflow and don't attach something in the MS Form, then I get an error.
- Rob_ElliottJan 04, 2024Bronze Contributor
What I do is to go to settings for the actions that relate to the optional file upload, go to settings and select Configure Run After and select Failed as well as is successful. The following images are from our IT Support Ticketing System where uploading a file is not mandatory.
So even if the individual actions actions relating to the file upload fail the flow continues to run and will be shown in the run history as succeeded.
Rob
Los Gallardos
Microsoft Power Automate Community Super User.
Principal Consultant, SharePoint and Power Platform WSP Global (and classic 1967 Morris Traveller driver)- rolaogomesFeb 15, 2024Copper ContributorI can't find the UploadedFile Action. ANy help? 😐
- rlehrawaacaDec 10, 2023Copper Contributor
RobElliott i am unable to use picker for selecting one drive folder.
- Rob_ElliottDec 12, 2023Bronze Contributor
rlehrawaaca why not? You can just type the folder path in the field:
Rob
Los Gallardos
Microsoft Power Automate Community Super User.
Principal Consultant, SharePoint and Power Platform WSP (and classic 1967 Morris Traveller driver)
- ANWOG242Jul 03, 2023Copper Contributor
Thanks for your guidance!
I have followed your suggestion to set the flow and it can transfer the attachments to SharePoint List successfully. But when I try to attach one photo and one video in the form and submitted, I can only open the photo but not the video in the SharePoint list. And when I attach only the video in the form, it is ok to open the video.
Just wonder if there is any extra step I have to build in in my flow in order to solve this issue?
Thanks!
Regards,
Ann
- babak1990Jun 27, 2023Copper Contributor
Hi Rob,
I followed the steps as you mentioned. however, I get an error "A potentially dangerous Request.Path value was detected from the client (?)." this error heppens on the "Get file content using path" step, where my file path is my sharepoint folder on the company domani. any idea how to resolve this? thanks.
- DingkunXieJun 28, 2023
Microsoft
- zalikha_joharMay 24, 2023Copper Contributor
RobElliott , why do I still get error message even though i have change to my path as below
{"status": 404,"message": "The resource could not be found.","source": "api.connectorp.svc.ms"}this is my path (group sharepoint)
.
even i have tried so many different method including yours, stil get error message.
And this is my connection. is it because of this?
Please advise what needs to be done.
Thank you in advance.
- CROKatFeb 26, 2023Copper ContributorHey Rob, when I follow this I get a failure notification that says the schema validation failed. Do you know what this error could mean? I copied your schema exactly.
- ChrisC475Nov 09, 2022Copper Contributor
You are a genius, that has just solved an issue for a beginner, thank you