• Yash Agarwal

Working with Files on MS Forms in MS Power Automate

In this #PowerShot, I will show you how to use the 'Upload File' option on MS Forms and then access that file to perform further operations using MS Power Automate.


The upload a file type question on MS Forms, first creates a folder with the name of the Form (or quiz) in OneDrive for Business of the user that is creating the form. All the files that are uploaded as a part of this form will be then saved in that folder.


While creating the 'Upload File' question on the form, you can provide restrictions to the number, size and extension of the files that the responder can upload. Note that the forms with the 'Upload File' type of questions can be shared with people within the organization only.


Let's Get Started!


In this demo, we will create a simple quiz type form with two questions, one that allows the responder to add text data and another that allows the user to upload a file. We will then trigger a Flow in MS Power Automate when a user responds to this form and then access the user responses to populate an email, add the uploaded file as an email attachment on a 'Send an Email' action.


MS Forms


For a simple demo, I created this quiz type form that has two questions.


Q1: Enter comments (that allows responder to enter some text on the form).


Q2: Upload a file (that allows the user to upload a single file of max size 10MB).

MS Power Automate


Step 1: Trigger: When a new response is submitted using the MS Forms trigger. Select the newly created form from the drop-down.


Step 2: Action: Get response details: to get the response details from the submitted form. Select the form and the response ID for this action.


Step 3: Action: Parse JSON: This action is a very import one here as the response of the form contains the Upload File questions' answer in the form of a string. This string is basically an array of objects that contains the file name, link to item and such details. The schema used in the parse JSON action is:

{ "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" ] } }

Step 4: Action: Get file content using path from OneDrive for Business. The new folder for the Form is created at the path as shown in the screenshot below. If you hit the save button before changing the name of the Form, the folder will be created with the original name and then followed by the Question. After selecting the folder path, use the following expression to access the file name:

Expression: first(body('Parse_JSON'))?['name']


Step 5: Action: Send an email: Here, you can add the custom body and use the below expression to access the link to the file:

Expression: first(body('Parse_JSON'))?['link']

Similarly, use the above 'name' expression in the file name and select the file content from the outputs of step 4.

//Added on 16 Jan 2020.


With multiple attachments to a single question on the Form


Step: After the Parse JSON action, intialize a variable of type array to store all the files.


Step: Control: Apply to each: For each item in the body of the file question,


//Start Loop


Step: Action: Get file content using path: to get the file content of individual items from OneDrive.


Step: Action: Append to array variable:

{

"Name": "@{items('Apply_to_each')['name']}",

"ContentBytes": @{base64(body('Get_file_content_using_path'))}

}

This appends each individual file to the variable and we are using the "ContentBytes" key to store the file content.


//Loop Ends

Step: Action: Send email action: select the array input and then pass the above created array in the attachments field.

//Added on 30 Mar 2020.


Check if the attachment has been added on the form or not

Setup a condition to check if the file question is empty. In the left side, switch to the expression editor and type empty and then select the upload file question and check if it is false to confirm an attachment has been uploaded.

In this article we saw how to access files uploaded on an MS Form from MS Power Automate and send it as an email attachment. Similar approach can be used when trying to record the form responses on SharePoint lists or other such data sources and the files can be accessed from the OneDrive folder.


I hope you found this interesting and it helped you!

Recent Posts

See All

Working with Throttling Limits in Power Automate

In this #PowerShot, I will show you how to better handle throttling limits for API requests actions, connectors and flow runs in Power Automate. Let's Get Started Connectors in Power Automate have a s

SUBSCRIBE VIA EMAIL

Yash Agarwal

  • Black LinkedIn Icon
  • Black Twitter Icon
  • Black Facebook Icon
  • Black Instagram Icon
  • Black RSS Icon

© 2019 By the Devs