cancel
Showing results for 
Search instead for 
Did you mean: 
Pstork1

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.

  1. 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.
    image.png
  2. 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.
    image.png
  3. 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.
    image.png
  4. 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.
    image.png
  5. 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.
    image.png

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

Perfectly explain each and everything that is necessary to emailing file attachments from forms with power automation. i really impress and keep it up, Guys.

 

@Pstork1 - Thank you for this.  I am having a bit of trouble with this - as well as some other methods I have tried.  I am able to get the flow to send the email - but the content of the file is unable to be opened.  I am either getting File not recognized, or if I open (a PDF for example) - it will show the correct # of pages, but not any content.  

 

timfros1_0-1685026191898.png

I have a condition to filter out if there is a file attachment or not, since it is an optional field on the form.

timfros1_1-1685026244969.png

 

My JSON code:

{
    "type": "array",
    "items": {
        "type": "object",
        "properties": {
            "name": {
                "type": "string"
            },
            "link": {
                "type": "string"
            },
            "id": {
                "type": "string"
            }
        }
    }
}

 

timfros1_2-1685026282044.png

 

timfros1_3-1685026326373.png

 

The attachments were two pictures and a PDF...

 

timfros1_4-1685026429680.png

 

Any help or guidance would be appreciated!  

 

Thanks,

Tim

 

I don't think your condition will do what you want it to. JSON is a string which normally isn't null, but may be blank. Null and blank aren't the same thing.

 

For the empty files double check in a recent run with an attachment to make sure that your step to Get file content is actually retrieving something. Also, the name and file content shouldn't be in quotes.  That may be the source of your problem.  Compare the screenshot from my step #4 with yours.

Thank you!  It was the quotes....much appreciated, as always!

Hello @Pstork1 , thank you for the wonderful post. It has worked very well for me in the past but for some reason, it now seems to be throwing an Error in my Get file content.

 

deimos_0-1686003504255.png 

 

deimos_2-1686003812514.png

 

 

When I inspect the Output of Parse JSON, the link leads to the file correctly and the id matches the Input File ID (crossed out above).

 

Do you have any ideas of why this is happening?


Below is my workflow leading up to where the error is thrown.

deimos_1-1686003766040.png

 

Cheers,
D.

@deimos The only thing I can figure is some kind of timing conflict due to service slowdowns yesterday. If the file is there then this should work.  I've never seen the issue you are seeing.

How do you "Run your flow once at this point to get some sample output that you can use to generate the JSON schema." I have ran the flow, but not sure where to get the sample output?

When you look at the details of the flow you will see the flow run.  If you click into that each action will show you inputs and outputs.  You can highlight the output you need and use a Control-C to copy it.

Hi @PS , thanks for the blog post, it is exactly what I'm looking for.

 

Im having some trouble on the part where 'get file content' for onedrive for business is getting the file from my personal onedrive for business instead of the teams channel sharepoint folder. 

 

is there any way I can do to fix the source?

@Pstork1 Similar to @timfros1, our Microsoft Forms attachment question is optional.  However, we may have a situation where the requestor may attach more than one attachment.  When they do so, mulitple emails are sent with either 1, 2 or all 3 of the attachments.  Below is my flow:

 

Shannah_0-1707408491975.png

Conditional attachment:

Shannah_1-1707408516815.png

If attachment then this workflow:

Shannah_2-1707408548558.png

But we get an email for each attachment starting with 1 attachment, then 2 attachments, and so on.  What am I missing? Thank you!

 

Take a look at Step 4 and 5 again. You have the Send an email inside the loop where the attachments are appended to the variable. That should be outside the loop but inside the yes side of the condition.

@Pstork1 Perfect!  This worked.  Thank you!

@Pstork1 Do you know if it is possible to have several branching questions that may include attachments (condition), and still have an email with all the details included? I am stuck on my first branch. The question is, is it a vendor or client contract, if Client - then the condition is No (and populates the data for the Vendor info.  I can get the email, but I can't get the actual files attached in the email.

First steps:

Shannah_1-1710515346609.png

 

No = Vendor

 

Shannah_2-1710515400543.png

If yes, then attachment should send and if no, then no means attachment (which that is sending).

 

Shannah_3-1710515463465.png

Shannah_4-1710515478941.png

 

Shannah_5-1710515496350.png

 

All though it says it ran successfully, it did not.  When I go to the steps above, I get this message:

 

Shannah_6-1710515584637.png

What am I doing wrong?  Thank you in advance.

 

 

Yes its possible. The key is to save all the information that you want in the email into a text variable until you get to the end of the flow. Do the same with any attachments, by adding them to an attachments array. Then at the end all you need to do is have a single condition that checks to see if the length of the attachments array is greater than 0. If it is send the email using the variable and the attachments array. If its not then just send the email using the variable and no attachments array.

@Pstork1 I am going in circles. I am feeling very dense as I have tried every variation I can think of, and I am getting nowhere.  Where and what is the step I am missing?  Thank you in advance.

@Shannah Are you getting any error messages? Can you provide some screenshots of what you have done? Its hard to predict what you are missing if I can't see what you have done.

@Pstork1 Here is one (similar to the example I used above).

The Json is linke to the Attachment in the question, and 'contains" an File Array, 

Shannah_0-1710778841490.png

It says it was a success (which I do get an email), but without the attachement.

 

Shannah_2-1710778895411.png

 

 

@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.

@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:

File Array greater than 0.png

 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:

 

Does not Contain 0.png

 

Thank you for all the help.  I really appreciat it.

 

@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.

image.png

and the result of the condition looks like this

image.png

Unfortunately, I cannot attach a FIleArray in the email via attachment

Philarius_0-1714031424263.png

 

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.

image.png

@Pstork1

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.

 

Philarius_0-1714058851186.png

 

Philarius_1-1714058871119.png

 

Philarius_2-1714058894066.png

 



 

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.

@Pstork1 sorry for the misunderstanding i got the same problem like @Shannah 

Philarius_0-1714065044041.png

Philarius_1-1714065253160.png

 

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.

@Philarius 

 

I found this video very helpful for my issue.

 

https://youtu.be/kNC8q6NzBEc?si=HwarkjbWtcqMhObG

About the Author
  • Experienced Consultant with a demonstrated history of working in the information technology and services industry. Skilled in Office 365, Azure, SharePoint Online, PowerShell, Nintex, K2, SharePoint Designer workflow automation, PowerApps, Microsoft Flow, PowerShell, Active Directory, Operating Systems, Networking, and JavaScript. Strong consulting professional with a Bachelor of Engineering (B.E.) focused in Information Technology from Mumbai University.
  • I am a Microsoft Business Applications MVP and a Senior Manager at EY. I am a technology enthusiast and problem solver. I work/speak/blog/Vlog on Microsoft technology, including Office 365, Power Apps, Power Automate, SharePoint, and Teams Etc. I am helping global clients on Power Platform adoption and empowering them with Power Platform possibilities, capabilities, and easiness. I am a leader of the Houston Power Platform User Group and Power Automate community superuser. I love traveling , exploring new places, and meeting people from different cultures.
  • Read more about me and my achievements at: https://ganeshsanapblogs.wordpress.com/about MCT | SharePoint, Microsoft 365 and Power Platform Consultant | Contributor on SharePoint StackExchange, MSFT Techcommunity
  • Encodian Owner / Founder - Ex Microsoft Consulting Services - Architect / Developer - 20 years in SharePoint - PowerPlatform Fan
  • Founder of SKILLFUL SARDINE, a company focused on productivity and the Power Platform. You can find me on LinkedIn: https://linkedin.com/in/manueltgomes and twitter http://twitter.com/manueltgomes. I also write at https://www.manueltgomes.com, so if you want some Power Automate, SharePoint or Power Apps content I'm your guy 🙂
  • I am the Owner/Principal Architect at Don't Pa..Panic Consulting. I've been working in the information technology industry for over 30 years, and have played key roles in several enterprise SharePoint architectural design review, Intranet deployment, application development, and migration projects. I've been a Microsoft Most Valuable Professional (MVP) 15 consecutive years and am also a Microsoft Certified SharePoint Masters (MCSM) since 2013.
  • Big fan of Power Platform technologies and implemented many solutions.
  • Passionate #Programmer #SharePoint #SPFx #M365 #Power Platform| Microsoft MVP | SharePoint StackOverflow, Github, PnP contributor
  • Web site – https://kamdaryash.wordpress.com Youtube channel - https://www.youtube.com/channel/UCM149rFkLNgerSvgDVeYTZQ/