How to send Microsoft Forms file uploads to an Approval workflow using Power Automate

This is a quick beginner’s tutorial for creating an approval workflow using file attachments that have been uploaded from a Microsoft Form. The flow will attach these files to the approval action. The flow will work if multiple files were uploaded. The steps in the flow will be:

  1. A user completes a Microsoft Form and uploads files
  2. Get the user’s Forms response
  3. For each file that was uploaded, get its filename and content (uploaded files are stored in OneDrive)
  4. Create an Approval and add attachments to the approval action
Example Microsoft Form. The form contains a file upload control.
Example Application form created with Microsoft Forms showing the file upload control in Question 6.

The flow assumes that the Application form has only one file upload control. If your form has multiple file upload controls then see How to send Microsoft Forms file uploads from multiple questions to an Approval workflow using Power Automate.

The flow assumes that the Application form has only one file upload control.  However, your form could have multiple file upload controls as we see in the example form called Weekly Menu Upload.

The flow assumes that the Application form has only one file upload control. However, your form could have multiple file upload controls as we see in the example form called Weekly Menu Upload.

The flow also assumes that file uploads are a required field meaning that users are required to attach a file before submitting the Application form:

The flow assumes that file uploads are a requied field meaning that users need to attach a file before submittig the form
The flow assumes that file uploads are a required field

If file uploads are optional in your form, then continue to follow the tutorial below, then make the changes as shown in the section Form is submitted without an uploaded file and the flow fails .

Here is the entire flow

Here is the entire flow.

Get the Forms response and initialize an array variable

We get the form response and initialize an array variable. The array variable will be used to store the attachment filenames and content:

The get the form response and initialize an array variable.

The Apply to each loop

We need to loop through the details about each file that was uploaded and for that we will use the Apply to each loop.

We then need to get the following information about each file:

  • filename
  • file content

and then append the filename and file content to the attachments array.

We need the filename and content of the uploaded file. We then append this information to the attachments array.

This is the overall view of the Apply to each loop. I will break this down into their individual actions below:

The overall view of the Apply to each loop
The Apply to each loop. Click on the image above for a larger view of this part of the flow.

The Apply to each loop requires information about the uploaded files to be in JSON format. We can construct an expression get this information into JSON format by “wrapping” the dynamic content for the Upload your file property inside a json function:

The apply to each loop requires information about the uploaded files to be in JSON format.
“Wrap” the dynamic content for the Upload your file property inside a JSON function. Click on the image above for a larger view of this part of the flow.
How to “Wrap” the dynamic content for the Upload your file property inside a JSON function.

Get file metadata Action

Add a Get file metadata action:

Close up of the Get file metadata action
The Get file metadata action. Click on the image above for a larger view of this part of the flow.

and use the following expression as the file value:

items('Apply_to_each')?['id']

This action will later help us easily get the name of the uploaded file and its content.

Get file content action

Next we get the file content using the Get file content action as shown below:

Close up of the get file content action
The Get file content action. Click on the image above for a larger view of this part of the flow.

Fill the array with the filename and file content

Add (append) the filename (Display name) and file content to the attachments array:

Click on the image above for a larger view of this part of the flow.

Here is closer view of the append to array action. The content of the array requires a specific format if it is going to be used as an attachment in the approval action:

Here is closer view of the append to array action. The content requires the following  specific format if it is going to be used as an attachment in an approval action.
The content of the array requires a specific format if it is going to be used as an attachment in an approval action

You can type the content in manually or you can copy-and-paste the following code:

{
  "name": @{outputs('Get_file_metadata')?['body/DisplayName']},
  "content": @{body('Get_file_content')}
}

The Approval action

Add an approval action (e.g. Start and Wait for an approval) and insert the array variable in to the approval action:

Approval actions with attachments
When adding the attachments array variable you need to switch to “input the entire array” mode.

And that’s it for the flow.


Runtime outputs

Here is an example forms file with three files that have been uploaded:

Here is an example of a forms file upload
Forms file upload with three files attached

Example email notification

Note that the file attachments have been sent along with the email notification:

Example email notification.  Note that the file attachments have been sent along with the email notification.
Example approval workflow email notification

Example Teams approval notification

Note that file attachments don’t appear in Teams approvals:

Example Teams approval notification.  Note that the file attachments don't appear in Teams approvals:

This may be a bug or a limitation of the current approvals notification sent by Power Automate. Have you found a way to make the attachments appear in the Teams app?


Attachments not appearing in the approval notification message?

I have found that forms file attachments only appear in the email approval notification sent by Power Automate. File attachments don’t appear in the Teams approval so make sure that you have enabled notifications for the approval action. By enabling this setting Power Automate will send an email notification messages to the approver:

So make sure you enable notifications for the approval action:

Corrupt attachments? Attachments won’t open?

Attachments won't open

Different solutions on how to construct the attachments array have been discussed in Power Automate forums. The flow I have presented here seems to work with Forms file attachments for approval workflows.

However, if you find that in some instances the above does not work, i.e., the file attachment won’t open, I have included an alternative format for the attachments array.

You can copy and paste the following code in to the Append to Approval Attachments array variable action as shown above:

{
  "name": @{outputs('Get_file_metadata')?['body/DisplayName']},
  "content": {
    "$content-type": @{body('Get_file_content')?['$content-type']},
    "$content": @{body('Get_file_content')?['$content']}
  }
}

For further information about this, see:


Form is submitted without an uploaded file and the flow fails

If a file upload is an optional requirement in your form, a user could submit a form without a file and this will cause the flow to fail as there will be no file for the flow to process:

The flow failed because no file was loaded with the form.
The flow failed because no file was loaded with the form.
Action 'Apply_to_each' failed
Action ‘Apply_to_each’ failed

To fix the error you could (1) make the file upload a required field, or (2) change the flow to handle the situation if no file was uploaded.

Option 1: Make the file upload a required field

To fix this make the file upload a required field. The flow does not need to be changed.

A simple way to fix the error is to make the file upload a required field

Option 2: Change the flow to handle no file uploads

We can determine whether a file was uploaded or not by checking the forms response. We need to look at the content of the file upload field (property) shown below as Upload your file :

We can determine whether a file (or files) was uploaded examining the forms response

The Upload your file propetry field (it’s actual internal name inside my flow is r39184e70bc0845338547b8ac381488fd) will be empty if no files were uploaded. If a file was submitted with the form it will not be empty:

The file upload field will be empty if no files were uploaded. It will not be empty if a file was submitted with the form
The file upload field will be empty if no files were uploaded.

So let’s add a condition action to the flow to check whether the Upload your file property is NOT empty (i.e. it contains a file).

Check if the file upload field contains a file.
Check if the file upload field contains a file.

If the file upload field is not empty a file was uploaded and we can continue with the approval workflow as before. But if no file was uploaded, the flow will end at this point and we will take no further action in this demo flow as the purpose of the flow is to approve the file uploads. You can add actions to the No block below for when no file was uploaded by the user, such as sending an email to the submitter asking them to submit the approval if required.

If the file upload field is not empty then we can continue with the approval workflow
If the file upload field is not empty then we can continue with the approval workflow

The updated flow should now looks like this:

Image of the updated flow. If no file was uploaded, the flow will end and no further action will be taken.
The updated flow. t if no file was uploaded, the flow will end at this point

Alternative ending…

However, if you may want to still continue with the approval workflow even when a file was not uploaded. We need to make another change. Move the Start and wait for an approval action to the end of the flow. You should be able to select the Start and wait for an approval action and drag it outside of the Yes block:

Move the start and wait for an approval action to the end of the flow
Move the Start and wait for an approval action to the end of the flow
Select the Start and wait for an approval action and drag it outside of the Yes block
Select the Start and wait for an approval action and drag it outside of the Yes block

The updated flow now looks like this:

If you still want to continue with the approval workflow but without a document for approval, change the flow to the above
If you still want to continue with the approval workflow but without a document for approval, change the flow to the above


8 thoughts on “How to send Microsoft Forms file uploads to an Approval workflow using Power Automate

Add yours

  1. Thanks for sharing this. I tried to implement it, but I’m running into an issue where if a Form is submitted without an uploaded file, the flow fails. Do you know a way to make this work regardless of whether a document is uploaded or not?

    Thanks!

  2. Hi Patrick,
    Thanks for your comment. I have added a section to the end of the post that shows how to handle the situation where a file upload is an optional requirement for a form and the user submitted a form without uploading any files. Hope this helps.

    Ellis

    1. Hi Mr. E. Karim,
      Please, can you help me? I need to upload attachment from different questions on forms and send all together in the same approval .
      Thanks a lot and have a nice weekend
      Tiago A.

  3. Hi Karim,

    Thanks for writing this blog. I followed your flow exactly as you stated. I successfully received the email with the attachments in my approval email. However, I’m unable to open the documents. Need your help to rectify this issue. Thanks

    1. Hi Victor,

      Thanks for posting this question.

      I’ve updated the section “Corrupt attachments? Attachments won’t open?” in the blog post. This update offers a different format for the “append to array” action:

      {
      “name”: @{outputs(‘Get_file_metadata’)?[‘body/DisplayName’]},
      “content”: {
      “$content-type”: @{body(‘Get_file_content’)?[‘$content-type’]},
      “$content”: @{body(‘Get_file_content’)?[‘$content’]}
      }
      }

      I’ve created and tested a demo flow, and this should fix the issue.

      Recently on the Power Automate Community forums a number of users have report the same issue, the most extreme example being:
      https://powerusers.microsoft.com/t5/Building-Flows/Uploading-Excel-email-attachments-to-SharePoint-library/m-p/1768698#M195571

      The question that still needs to be answered is: Why do different array format work for some people but generate corrupt attachments for others?

      Hope this helps.

      Ellis

      1. Hi Karim,

        Thanks for the quick response. I’ll try this out and appreciate all your sharings!!

        Blessings

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Website Built with WordPress.com.

Up ↑

%d bloggers like this: