Emailing File Attachments from Forms with Power Automate
I’ve seen some questions recently on the Power Platform Forums about how to send multiple attachments submitted in Microsoft Forms in an email. Since this seems to be a common problem I thought it would be good to walk through the steps in a BLOG post.
- Once you have a Microsoft Form created that includes a question with an attachment you can create a new Power Automate Flow that uses the “When a new response is submitted” trigger. That will start your flow each time a response is submitted through Microsoft Forms. But the trigger alone won’t provide enough detail about what is in the response. So you also need to add a “Get response details” action to retrieve the questions and the answers submitted in the form.
- In order to submit more than one file attachment to the email you will need to create an array to hold the name and content of each file. To do this we “Initialize a variable” of type array. We will supply values for the array later in an “Apply to each” loop.
- Now you are ready to retrieve the details of the files attached to the question in the response and add them to the array. To do that you need to use “Parse JSON” to parse the contents of the question in the response where the files were uploaded. Run your flow once at this point to get some sample output that you can use to generate the JSON schema. Then add your question content to the Parse JSON.
- Files uploaded to a Microsoft Form are automatically stored in the Form creator’s OneDrive for Business account. So now that we have access to the details of those files from the Parse JSON action we can retrieve the file content from OneDrive and append it to the Array we created in Step #2. We’ll use the file id to retrieve the file and then add the Name of the file and the File content to the array. Whether there is one file or multiple files the details will be in an array, so we’ll need to use an “Apply to each” loop to get each file and append it. The File content can ge used directly as we retrieve it from OneDrive. No translation to Base64 is required because the file is retrieved as JSON, not binary.
- Now that we have the file content in an array we can send the email. Be sure to click on the selector in the attachments section to switch from detail inputs to an array item. Then just fill out the email and add the array variable to the Attachments field.
Now you can save and test your flow by filling out the Microsoft Form and uploading one or more attachments to the form. In under 5 minutes you should get an email with the attachments from the form.
Comments
-
Emailing File Attachments from Forms with Power Automate
I found this video very helpful for my issue.
-
Emailing File Attachments from Forms with Power Automate
There is a problem in your Parse JSON. You are trying to get a file, but no file was uploaded in that question so the content is NULL. That's not the same problem as @Shannah . You need to make sure there is a file before you try to parse it and use the value.
-
Emailing File Attachments from Forms with Power Automate
Are the attachments uploaded into different questions for each department? If not, how do you know that the file uploaded is from a specific department?
I would suggest posting this as a question in the forums, since this takes it beyond the scope of the article here.
-
Emailing File Attachments from Forms with Power Automate
Thank you, that worked
Now I have the problem that if no file is uploaded, no message arrives. I'm a bit at a loss as to how to implement this.
I query 2 departments via the form. Franchise and Customer Service
Now I want to check for each department whether an attachment has been uploaded in the form. If yes, then an email should be sent informing them that an upload has taken place.
Even if no file has been uploaded in Forms, a message should be sent via email that there is no attachment. -
Emailing File Attachments from Forms with Power Automate
Click on the icon above and to the right of the attachments section. That toggles the interface between inputting a single attachment and an array of attachments. See Step#5 in the article.
-
Emailing File Attachments from Forms with Power Automate
Unfortunately, I cannot attach a FIleArray in the email via attachment
-
Emailing File Attachments from Forms with Power Automate
@Shannah The condition is to check the length of the array. To do that you need to use the Length() function. The result of that is what you check against 0, not the file array itself. If you add it to the walkthrough in this blog it looks like this. You are checking the length of the file array that you are adding the attachments from the form to.
and the result of the condition looks like this
-
Emailing File Attachments from Forms with Power Automate
@Pstork1 Yes, the condition is whether there is an attachment or not.
I get this following error when I use the condition File Array greater than 0:
But when I use File Array either "does not contain 0" or "Not Equal to 0", it sends the attachment, but then when the form is completed without an attachment, I get the following error:
Thank you for all the help. I really appreciat it.
-
Emailing File Attachments from Forms with Power Automate
@Shannah What are you trying to do with Condition 7? You aren't getting any files because that is evaluating as null. If you are trying to check whether that question has attachments or not then the right thing to do is to test the length of the file array. If its greater than 0 there are files present. But that won't use the JSON() function.
*This post is locked for comments