cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
grantreid
Resolver I
Resolver I

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
Community Champion
Community Champion

@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
Community Champion
Community Champion

@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

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

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

New Ideas Forum MPA.jpg

A new place to submit your Ideas for Power Automate

Announcing a new way to share your feedback with the Power Automate Team.

Carousel_PP_768x460_Wave2 (1).png

2022 Release Wave 2 Plan

Power Platform release plan for the 2022 release wave 2 describes all new features releasing from October 2022 through March 2023.

MPA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

365 EduCon 768x460.png

Microsoft 365 EduCon

Join us for two optional days of workshops and a 3-day conference, you can choose from over 130 sessions in multiple tracks and 25 workshops.

Users online (5,102)