Hi,
Is there way to exist from apply to each loop?
Thanks,
Upendra Singh
Here's how to change your loop to use a Do Until Loop, which you can break out of.
1) Initialize two variables, one to hold the number of items returned by the Get Items and the other as a Boolean set to False.
2) Use a DoUntil Loop to iterate through the items returned by Get Items. When you want to break out of the Loop set the Boolean variable to True. The loop will terminate on the next iteration.
3) Access the values of the items inside the loop using iterationIndex as an index on the collection. For example this JSON returns the Title property of one the current Get Items list item.
body('Get_items')?['value'][iterationIndexes('Do_until')]?['Title']
Hi @v-upsi ,
If you don't know the place the item you needed, I'm afraid that your requirement couldn't be achieved in Microsoft flow currently.
Best Regards,
Alice
Community Support Team _ Alice Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Does your 'Apply to each' contain only the Condition action block? If so, you can probably replace both 'Apply to each' and 'Condition', add 'Filter array' action block instead
Hope this helps
You are right, current iteration will fail, but the loop will start next iteration. That's why I call the suggested workaround as 'partial'.
Hope this helps
In an apply to each loop failing an individual iteration will make the loop go on to the next iteration of the loop. As I said if you want to be able to break out of a loop you'll need to use a do until loop set to exit after either setting a control variable to a certain value or iterating through the last item.
I just explain as example because if it's apply to each so I don't know when this condition will match, it might match at first iteration, second and so on. So when that condition match then it will exist from each loop.
Thanks
Upendra Singh
Hi @v-upsi ,
If you just want to check the first item in the array, you could create the flow as below:
body('Get_items')?['value']?['0']
outputs('Compose_3')?['Title']
Best Regards,
Alice
Community Support Team _ Alice Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi @Pstork1
Thanks for your suggestion on this. I just want to know if add some logic inside the apply to each condition to fail the steps so what will happen if i have other step next to apply to each, it will also fail to run which i don't want.
I have other step which use this apply to each condition value and perform some other action.
Thanks,
Upendra Singh
I have apply to each condition where i have added some condition to validate so what i want is while iterating the loop if condition meet at first iteration so my apply to each condition should exist from first iteration and it should not iterated remaining items from loop. And after apply to each there is other step which depend on condition value which should execute.
WarrenBelz
146,645
Most Valuable Professional
RandyHayes
76,287
Super User 2024 Season 1
Pstork1
65,997
Most Valuable Professional