Power Automate is forcing encapsulating "Apply To Each" steps where I don't want them. Or at least I don't understand why they are being forced there. One is resulting in endless loops.
My flow:
TRIGGER - Email added to outlook folder
Regular Expression Match (Plumsail's) on the subject
Get Rows - A client table from google sheet
Filter Array - To get a client email address using a client name from the email subject above.
Repeat last two steps for a different table and address.
Add a row to a google sheets table for a log
Email myself a test email
Step 1 - Only returns one email each time.
Steps 2 - 7 are shown below.
Step 4 the repeated 4 are forced by Power Automate to be inside of Apply to Each steps. Why?
Step 6 is also forced to be inside an Apply to Each step. Why?
Step 7 is forced to be inside 3 Apply to Each steps. I assume it's because I'm referencing parameters from three steps above which are also inside Apply to Each steps. This is causing countless emails to be sent and the flow times out.
People on the Plumsail forum suggested I use dynamic content Match0 (a single record) instead of Matches (an array) in my Filter Array steps. When I try that the flow forces ANOTHER encapsulating Apply to Each with Matches. Huh?
PRIMARY QUESTION: How do I stop the endless loop of emails being sent and send only ONE.
Other questions:
1. Why is this happening?
2. Why does Apply to Each get forced on my by Power Automate?
3. If it is a "feature" please point me to some documentation so I can understand it.
Thanks very very much whomever you are out there with the simple answer that I am lacking.
First here is the summary flow. Further below is the expanded.
A condition will always have an apply to each (for each loop) if multiple items are returned or compared, even if you are just searching/filtering. The only time you won't utilize an apply to each, is when dealing with a single item, such as a get file or get item. If you use a get files, or get items, you'll nearly always have a loop. If you'd like to avoid them, see here - Avoid unwanted apply to each steps in Power Automate (sharepains.com).
If this reply answers your question or solves your issue, please ACCEPT AS SOLUTION ☑️. If you find this reply helpful, please consider giving it a LIKE.
The problem is that when filtering an array you will always get the output as an array, even if only one match was found. If you are sure there will only be one match then you can use the Expressions tab of the dynamic content dialog to get the first item in the array that was returned. That way it won't automatically create an Apply to Each loop.
I still haven't figured this out.
I'll certainly post an answer when I do.
Thanks everyone.
Any further hints would be helpful.