Hi, my flow is an instant flow as below (I've blurred the sensitive information).
I have Excel files saved in a SharePoint folder for different people (file name convention = person's name + Month/Year) and I need to send these files to each of them via email. I also have an Excel table (Contact List) where I've got people's names, month/year, file names and email addresses.
What this flow does is that when I select the row (i.e., file name) from the Contact List, it looks for that file inside my SharePoint folder and send the file to the corresponding person via email.
Note that not all people get sent a file every month so the number of files to be sent each time will always less than the number of people in my Contact List.
My flow is running extremely slow and it took more than 3 min for each file to be sent. Although all files got sent eventually, it appeared to be failed in My Flow. I added "Terminate" when Failed at the end previously but it didn't help. I'm not sure where I did wrong.
@ricelover_888 As I mentioned before, this is because the Get Files (properties only) action will always return an array of files—even if it's only a single file. You need an expression to avoid the Apply to Each action. Refer to this section of my YT Tutorial on how to do that.
It automatically created an Apply to each step. I modified the File Identifier and it somehow works now.
@ricelover_888 As mentioned previously, if you are only ever expecting a single file—you should avoid the Apply to each action as it's not necessary. Refer to this section of my YT Tutorial on how to do that.
I can't tell which dynamic content you are using in the File Identifier field of the Get field content action. You'll need to ensure that it's the Identifier dynamic content.
Thanks. I applied your method and tested and successfully got 1 item per flow and the file returned was correct. However, I encountered an issue at Get file content. It said the file was not found.
@ricelover_888 The error shows that the file wasn't found. If you'd like to filter on the File Name, you'll need to use FileLeafRef in you ODATA filter query. Also, here's a fun fact. The Get Files (properties only) returns folders as well. You need to use a Filter Query to return Files only. Refer to this YT Short.
Whenever I use a Filter Query in a Get Files (properties only) action, I always like to return the count of items returned in a Compose action. This is helpful when building a flow and can also be used to troubleshoot your flow.
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. Review the output of the Compose action. See if the filter query has returned any files, if not—the Compose action will output a zero.
Add a Condition action to your flow. If files have returned (aka there is number stored in the Compose action—that is not equal to 0), add the rest of your actions to the Yes branch. If not, do nothing.
If you are only expecting 1 file to match, you'll want to avoid the Apply to Each action. Even if a single file has been returned from the Get files (properties only) action—it'll still return an array.
Take a look a this YT Tutorial: 3 Mistakes YOU 🫵 are Making with the Apply to Each Action in your Microsoft Power Automate Flow
In this video tutorial I’ll go over how to avoid these common mistakes when using the Apply to Each action in a Power Automate flow:
1️⃣ Looping through a Single Item
2️⃣ Creating Unnecessary Nested Loops
3️⃣ Looping through an Unfiltered Array
At the end of the video I share a few helpful insights when it comes to using the Apply to Each action in your flow.
IN THIS VIDEO:
✅ How to avoid the Apply to Each action with a single item array
✅ How to use the item() function to access dynamic content in an array
✅ How to prevent unnecessary nested Apply to Each action loops
✅ How to use the Select action
✅ How to convert an array to a string with the Select action
✅How to use the Filter Query field
✅ How to count the number of items in an array
✅ How to use a condition control
✅ How to use the concurrency control
✅ How to set a top count
✅ How to use Compose actions for troubleshooting
Thanks for the solution. I'll give it a go. Screenshot below is the detail of a failed flow.
@ricelover_888 Instead of using an Apply to Each and Condition action you should utilize the filter query field in the Get Files (properties only) action. Looping through each file in your document library and running a condition check on each file is inefficient.
Can you show a screenshot of where your flow is failing?
In the meantime, you might find this YT Tutorial helpful: 5 Power Automate Troubleshooting FAQs and Helpful Tips for Creating Better Flows
In this Power Automate tutorial, I explore 5 frequently asked questions that pop up when troubleshooting a flow. If you’d like to to level up your Power Automate flow skills and learn how to troubleshoot your Power Automate flow—this tutorial is for you!
IN THIS VIDEO:
✅ How to troubleshoot a false Condition action result
✅ How to get dynamic content when it isn’t selectable from the list of dynamic content
✅ How to troubleshoot an Apply to Each action that isn’t looping through
✅ How to troubleshoot a skipped Apply to Each action
✅ How to troubleshoot a Filter Query
✅ How to use a SharePoint yes/no column in a Filter Query
✅ How to use Compose actions to troubleshoot a Power Automate flow
✅ How to troubleshoot multiple emails being sent
✅ How to troubleshoot multiple Teams messages being sent