I think this will require multiple JSON expressions and Y/N conditions (for null) to allow for the flexibility of all the files I may need uploaded. I just am unfamiliar with how to build it.
Here is the general flow I am trying to achieve:
1. User submits an MS Form that has five sections and "branching" built-in to guide the user through the submission. Here is a snip of the beginning of the Form (total of 128x Questions, 8x of which allow the user to upload multiple files that are required depending on their responses.
2. The user might be required to upload multiple documents across 1-5x different questions, depending on their inputs.
3. I want these attachments to automate into a SharePoint List and simultaneously attached to an automated email.
I have been successful in getting up to 2x files uploaded into the SharePoint list and 1x file uploaded as an attachment in an email.
Here is the Problem I am trying to solve:
1) I am unclear how to build the flow to have more than 2x files across multiple MS Form questions and account for "null" answers. Here is the flow from MS Forms to my SharePoint List.
2) I am unclear how to build the email flow to have more than 1x file attached from the MS Form submission. Here is my flow from MS Forms to Email.
Thanks @creativeopinion
Not surprisingly - in the act of typing out my problem as a new questions I saw my error in the union code and solved my issue!
@Codatron It would be helpful to see a screenshot of your full flow. The union() function only accepts two parameters. It can only combine one array with another.
I'd also recommend starting a new post since this one has already been marked as solved.
Apologies for the hijack, but keen to tease out a similar problem. I have the same workflow effectively, except I am working with 13 file arrays. I understand that union can only combine 10 maximum parameters.
So, how can i combine all 13 into a single array to attach to my email?
Value your input!
@pbj2011 As suggested in my original post you should be testing your flow at each stage and troubleshoot at each stage before trying to build the full flow and troubleshoot later.
If you copy the File Path from the failed Get file content using path action and paste it into your browser. Does the file come up? If it does, it means that you might need to either add a delay before this action to ensure the file is fully uploaded before you try to run it—you could also add a delay at the start of the flow to ensure all files are uploaded before the rest of the actions in your flow run.
Alternatively you could add a Do Until loop.
You can also manually check your Document library to see if the file is there as well.
You've set up the condition check incorrectly. The value entered into the second value field should be zero not null.
In this particular flow run I purposely didn't upload any files. The output of the Compose action is zero.
When the condition check is run and the value in the second field is zero, it'll return false. This means there aren't any items returned.
However, if you insert the second value as null, it'll return true—which is "correct" but not the result you want. If there are zero files returned—you want the result to be false so that nothing happens. Or, if you do want actions to be taken if the result is false you need to add additional conditions to the NO branch.
The reason your attachments aren't being collected is that the JSON is formatted incorrectly. The JSON is case sensitive.
Name must have a capital N. ContentBytes must have a capital C and B.
Hope this helps!
If I helped you solve your problem—please mark my post as a solution ✅. Consider giving me a 👍 if you liked my response! |
I ran this entire flow. Here are the things that are not working with specifics below:
1. unable to find one of the three documents I attached in the MS Form.
2. did not attach the form to the email.
3. if a submission is received with no attachments, no email is sent.
Here is an overview of my flow and the error message I received:
ISSUE #1: unable to find one of the three documents I attached in the MS Form.
Error Message: "File not found clientRequestId: 0be37820-564f-41ac-919f-060a6d1af78f service RequestId: 0be37820-564f-41ac-919f-060a6d1af78f
Below is the precise structure of my flow:
Condition
Section 1 = 'Compose_-_Count_of_Files'
Apply to Each
Outputs = 'Compose_-_Combine_Uploaded_Files'
Get file content using path
File Path ='item()?['link']'
Compose - Attachment Name
Inputs = 'item()?['name']'
Add Attachment
File Name = "Compose_-_Attachment_Name'
I uploaded 3x files into this submission, only two attached successfully to the SP List. This meant that 5x files were "null" value. It seams like the flow ran correctly, but failed to find that 3rd attachment.
All other content was input into SP correctly without any issues. It was just that one attachment that I think failed to upload. But I could be wrong, still learning how to read PA.
ISSUE #2. did not attach the form to the email.
ISSUE #3. if a submission is received with no attachments, no email is sent.
I think this is a relatively easy fix. There are some instances where there will not zero attachments in a form submission. I think this means that I just need to mirror the "If yes" actions under the "If no" portion...unless this will send duplicate emails?
wow, extremely detailed. I'll build it out and let you know if I am able to get it to work, thanks!
@pbj2011 The logic of your flow needs a little adjusting. What you'll need to do is the following:
I'm only going to cover how to get the file uploads from your MS Form into SharePoint and attached to an email. If you need additional help on formatting your email or MS form responses— refer to this YT Tutorial I recently uploaded: How to Get a Microsoft Form RSVP Response into a SharePoint List
I cover the following in this video tutorial:
✅ How to get a Microsoft Form Response into SharePoint
✅ How to get a Microsoft Form ID
✅ How to get a Microsoft Form response
✅ How to Build a Microsoft Form with Conditional Fields
✅ How to used Branching in Microsoft Forms
✅ How to format Microsoft Form multiple choice responses for a SharePoint multi-choice column
✅ How to parse a Microsoft Form multiple choice response as string of text
✅ How to convert a text response to a number
✅ How to use the Switch action
✅ How to create a custom email confirmation for a Microsoft Form submission
✅ How to Create a Custom View in a SharePoint list
✅ How to use the Compose Action
✅ How to write Power Automate Expressions
In the tutorial I cover how to use a manual trigger so that you don't need to submit a form each time to trigger your flow. Please reference this section of the tutorial on how to do this.
I'm using a Scope action to group the next few actions in the flow. Scope actions are great because they help keep my flow organized. I can also quickly collapse multiple actions with a single click. The Scope action is optional.
Add a Compose action for each File Upload field in your form. For my demo I have 3 file upload fields.
Insert the json() expression. This function will convert the file upload details into a readable format—a JSON array.
Click on the Dynamic content tab and insert the appropriate MS Form output.
Repeat this step for each of the file upload fields in your form. Tip: Remember to rename your actions to keep your flow organized.
Next you'll need to combine the file upload JSON arrays into a single array. Add a Compose action. I've nested mine inside another Scope action (the Scope action is optional).
To combine arrays into a single array. You'll need an expression. First you'll need an expression to check if the array is empty. If it is, you'll need to output an empty array instead of a null value. You'll be using the union() function to combine the arrays and this function requires arrays. If you try to pass a null value you'll get an error.
To check if the array is empty, we'll need to use the empty() function.
Click on the Dynamic content tab and insert the output from the Compose action that is storing the response from the first file upload field. Note: This is why it's important to rename your actions. Otherwise things can get confusing really fast.
Next, we'll need to use the if() function.The if() function takes three parameters. The first parameter is a condition that returns a boolan value (aka true or false), the second parameter is the value that is returned if the condition is true. The last parameter is the value returned if the condition is false.
Go to the start of the expression by pressing the up arrow key and type in if with an opening parenthesis. Keep an eye out for the expression tooltip. It'll bold the text of the parameter you are currently setting.
Go to the end of the expression by pressing the down arrow key and enter a comma and insert:
json('[]')
This is the true value. In other words, if your array from the first file upload field is empty, it'll output an empty json array.
Add another comma and insert the output from the first file upload field again.
Add a closing parenthesis.
Your expression should look like this:
if(empty(outputs('Compose_-_Upload_Files_1')),json('[]'),outputs('Compose_-_Upload_Files_1'))
Keep in mind, if you've named your Compose actions differently than what i have in my flow, your expression will look slightly different.
Run a test. If your first file upload field does contain file uploads, you should see the details of those files in the outputs.
If your field doesn't contain any file uploads the Compose action will look like this:
If you click on the Click to download link—you'll see an empty array. This is what you want.
Because you have many file upload fields. It'll be a lot easier to compose your expression in a text editor. The expression editor in Power Automate makes it really hard to see the full expression.
Click on the expression label to open it up in the Expression field.
Copy the entire expression to your clipboard.
Paste it into a text editor. Add a comma at the end of the line.
Paste in as many lines as you need, ensuring that you add a comma after each line (except for the last line). In my case, I only have three file upload fields. You'll need to adjust the numbers for each line—this will only work if your Compose actions have the same syntax.
Next, wrap the entire expression in the union() function. The union() function will combine two or more arrays or collections into one and remove any duplicates in the process. In your scenario you don't need to worry about any duplicates as you are really using this function just to combine the arrays.
Copy this entire expression to your clipboard. Replace the existing expression with your new expression.
Use an expression to return the count of items from the Compose action above. This is can be helpful to troubleshoot.
Insert a Compose action. Add an Expression. Use the length() function.
Select the Dynamic content tab and insert the value dynamic content from the Get Items action into the length() function.
Run a test. Confirm the number in the Compose action output.
Add a Create Item action and insert any dynamic content where necessary.
Add an initialize variable action to your flow. Select Array as the type.
Add a Condition action to your flow. In the first value field, insert the output from the Compose action that is storing the count of files.
Change the operator to is not equal to and enter zero into the second value field.
In the YES branch add the rest of your actions.
Add an Apply to Each action into the YES branch. Insert the output from the Compose action with the array of files.
Add a Get file content using path action. You'll need this action to get each attachment's file content so that you can attach it the file to a SP item as well as an email.
In the File Path field, you'll need to use an expression to access the file path.
If you take a look at the output of the Compose action that combines the file arrays, you'll see the dynamic content. The expression we'll be using is the item() function. To access the dynamic content you'll need the dynamic content key. The dynamic content key is the text in red between the double quotes.
In this case, it's link.
Insert an expression:
item()?['link']
Because you'll need the attachment name in the next couple actions, I'd recommend using a Compose action to store it. You'll use the same expression as above, you just need to adjust the dynamic content key from link to name.
Add an Add attachment action to your flow. Ensure it's nested inside the Apply to Each action.
For the ID, you'll need to insert the ID from the Create Item action.
For the File Name, you can insert the output from the Compose action above.
For the File Content, insert the File Content dynamic content from the Get file content using path action.
Run a test. Check to see if your SP item has been created with attachments.
Add an Append to Array Variable action. Insert the following JSON.
{
"Name": [Insert Compose Action Output],
"ContentBytes": [Insert File Content]
}
Add a Send an Email (V2) action outside of the Apply to each action.
Click on Show advanced options. Click on the icon to switch to input entire array.
Insert the variable into the Attachments field.
Run a test. Ensure that the email has all of your attachments.
Hope this helps!
If I helped you solve your problem—please mark my post as a solution ✅. Consider giving me a 👍 if you liked my response! |
If you are looking for a way to send multiple SharePoint List items that have been assigned to a user in an email—check out this YT Tutorial: How to Send a SINGLE EMAIL ✉️ with multiple SharePoint list items | Build THIS Power Automate Flow
In this tutorial I cover:
✅ How to send multiple list items in a single email with a Power Automate Flow
✅ How to create a dynamic date range
✅ How to use the Convert Time Zone action
✅ How to use a Filter Query in the Get Items action
✅ How to count number of items in an array
✅ How to use the Select action to extract a users display name and email address
✅ How to create a unique list of email addresses
✅ How to use the Create HTML Table action
✅ How to customize the HTML Table with CSS styles
✅ How to use the Send an email (V2) action
✅ How to use the Append to String Variable action
✅ How to create a custom list of items for an email
✅ How to use the Send an email (V2) action
✅ How to display singular or plural text based on the number of items returned
Michael E. Gernaey
566
Super User 2025 Season 1
David_MA
516
Super User 2025 Season 1
stampcoin
492