cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
grantreid
Helper III
Helper III

Find record in array and break "apply to each"

I have an array of around 300 items and want to know the position of a certain record so I can find out what my Flow is doing when it hits that record.   I can't just keep hitting "next" until I find it in the flow run history. 

 

I thought I'd create a smaller flow with a "Do until"  which has "ID" = 123432 (the id number) and increments a variable. But.. Automate insists on putting this inside an "Apply to each".  I'm fairly certain this creates a viscous loop as I had to end the run after 15minutes. 

How do I find the position of a certain Id within an array and return that number?

2 ACCEPTED SOLUTIONS

Accepted Solutions
PrasadAthalye
Super User
Super User

@grantreid - You can declare a integer variable to 0 and increment within foreach using Increment variable action. Then when your id matches, you can set the value of this variable to another variable inside the match condition. Then use that variable to know the index..

 

Like and Mark this as solution if this resolves your issue.

Please Like and Mark this as Answer if it resolves your Issue.

Power Automate Community

View solution in original post

You can use Terminate Action to Terminate the flow as soon as you find a match.

Please Like and Mark this as Answer if it resolves your Issue.

Power Automate Community

View solution in original post

3 REPLIES 3
PrasadAthalye
Super User
Super User

@grantreid - You can declare a integer variable to 0 and increment within foreach using Increment variable action. Then when your id matches, you can set the value of this variable to another variable inside the match condition. Then use that variable to know the index..

 

Like and Mark this as solution if this resolves your issue.

Please Like and Mark this as Answer if it resolves your Issue.

Power Automate Community

View solution in original post

Yes, that would work. 

I still find it stupid that the Apply to Each is automatically inserted into the flow.  If I have 300 items in the array and the target is found at number 14... it still has to go through 300 iterations. 

You can use Terminate Action to Terminate the flow as soon as you find a match.

Please Like and Mark this as Answer if it resolves your Issue.

Power Automate Community

View solution in original post

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Top Solution Authors
Top Kudoed Authors
Users online (961)