cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anonymous
Not applicable

Nested Foreach loops?

Is there a way to create loop inside another loop?

 

I got an error: The template action 'Apply_to_each_3' at line '1' and column '2271' is not valid. Only actions of type other than 'foreach' are allowed to be nested under an action of type 'foreach'.

 

Screenshot_3.png

 

I need to get excel names from list and join rows from them to one file

1 ACCEPTED SOLUTION

Accepted Solutions
Anonymous
Not applicable

I found workaround using sharepoint list. But it will be good to have nested loops (at least one inside).

View solution in original post

6 REPLIES 6
v-monli-msft
Community Support
Community Support

Hi Unte,

 

According to my test, you cannot add loop inside another loop in Flow so far. In that case, you could create 2 separate flows. If you need my help to know how to achieve your requirement using two flows, please describe more clearly about your needs. Thanks.

 

Best regards,

Mona Li

Community Support Team _ Mona Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

I found workaround using sharepoint list. But it will be good to have nested loops (at least one inside).

What was your solution?

I'm guessing the solution was of this pattern: -

 

First workflow loops the source domain of items, running whatever actions, and writes each items into an SP list.

 

The list has a workflow attached triggered when a new item is added to the list.  So the workflow runs for each item added to this list, which de facto implements the first loop but allows a loop inside each execution of the workflow i.e. per item.

 

It works, but it's a sure way to burn through your Flow quota, coz you're running a Flow for each item to implement the second inner loop, rather than a running one Flow with two for each's in it.

 

Which is probably why MS engineered it this way.

 

Anonymous
Not applicable

Nested for each is available now. Just need to create variables in the first loop to hold values from the current item, and then look at the variable within the nested for each.

 

I thought the current iteration of the first for each would automatically be passed into the nested for each, but alas not. At least you won't have to burn through your flow quota like wildfire now!

Note that even after 5 years this implementation was imperfect. You cannot refer to actions in a loop if that loop is nested in another loop (the technique often used to compose the results from loop iterations.

Helpful resources

Announcements
Power Automate News & Announcements

Power Automate News & Announcements

Keep up to date with current events and community announcements in the Power Automate community.

Microsoft 365 Conference – December 6-8, 2022

Microsoft 365 Conference – December 6-8, 2022

Join us in Las Vegas to experience community, incredible learning opportunities, and connections that will help grow skills, know-how, and more.

Power Automate Community Blog

Power Automate Community Blog

Check out the latest Community Blog from the community!

Users online (2,783)