In my previous article I wrote about retrieving attachments from Microsoft Forms. The previous article covered forms that were linked to an individual, however if it is a group form the files are stored in the Document Library on the SharePoint site for the group instead of the form creators OneDrive. As a result of the different file location the process needs to be changed slightly.
To see how to get attachments from personal / individual forms please see the following link
In this article I will run through how to save the attachments from the Document Library on a SharePoint site.
Part 1: Setting up the form
In Microsoft Forms, go to Group Forms and select New group form
Then add the questions that you need to the form, including one with as a File Upload question which can be found in the drop down for the question types
Part 2: Setting Up the Sharepoint List
Depending on the information you want to capture from your form will depend on what columns you add to you SharePoint list
I have a SharePoint list set up called Issues and is used for capturing information about Defects or repairs for buildings
Part 3: Setting Up Power Automate
Once the form and SharePoint list are setup you are now ready to create the flow / automation using Power Automate.
In order to create the Flow you need to go into Power Automate and select Create. And since we want this process to happen automatically we will need to select Automated Flow
3.1 Setting up the trigger
The next step is to add a trigger, which in this case we will use the “When a new response is submitted”
Normally when working with Forms you can select the form from the Dropdown list of available forms in the Form Id field, however when working with Group Forms you may need to enter the Form ID as a custom value.
In order to get the Form ID you will need to go back to the form and copy the formID parameter from the URL
And paste it into the Form Id field after selecting Custom Value
We will then need to add the “Get response details” action and paste the Form Id into Form Id field again.
3.2 Creating Item in SharePoint
Once we have retrieved the data from the Form we can use the “Create Item” action for SharePoint. We will need to create a new item before we look at adding any attachments
Depending on the list you have these fields my vary.
3.3 Using the attachment data from the submitted form
The File Upload question will return details about the files uploaded in a JSON string. This is due to the type of information been returned for the uploaded files.
In order to be able to use the information about the files uploaded, you will need to use the “Parse JSON” action, this will convert the string into a useable array of objects, including the:
- Name of the file
- Link to the file
- Id of the file
The “Parse JSON” action requires the schema of the JSON to be able to interpret it, however we don’t need to work this out manually.
If we add a “Compose” action and pass in the results from the File Upload question we can then run a save and run the flow, submit a response in the form and the “Compose” action will provide us with the JSON returned
We can then copy the value from the Outputs field. Then go back to editing the flow.
We can then add a “Parse JSON” action and use the Generate from sample button and paste the Outputs value that we just copied and this will generate the JSON schema for us.
- Once you have the Schema setup for the “Parse JSON” action you go back and remove the “Compose” action from above
- If there is a chance that an attachment may not be added you can add a condition to see if the response to the file upload question is blank.
- The JSON will return an array even if there is only one matter the number of attachments
3.4 Getting file content
This is the main step that is different with Group Forms. If you are using Personal Forms then you can use the “Get file content” for OneDrive action, however with group forms the files are stored in the Document Library for the SharePoint site linked to the group.
Given that the “Parse JSON’ returns an array we will need use an “Apply to each” action and pass in the results from the “Parse JSON” action.
Then we can add the “Get file content using path” action for SharePoint.
3.5 Adding the attachment to the SharePoint list item
Once we have the file content we can use the “Add Attachment” action for Sharepoint to add the file to the previously created SharePoint item
Part 4: Wrap Up
That’s it, we should now be able to save and test the flow and see the information submitted through a Group Form in a SharePoint list, with any attachments.
I’ve included a screenshot of the entire flow below