cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
cgru3eejc2
Advocate IV
Advocate IV

For each index - incerement variable: how to get index?

Hi,

 

I guess I would like to do something similar as described here: https://powerusers.microsoft.com/t5/Building-Flows/Can-I-get-index-number-in-apply-to-each/m-p/46543...

 

 

I have an array, here as an example a very simple one and I do a for each over this array.

I would like (or should have) the index of the for each. No clue why the first array value has 3 as incremented variable. It seams the for each are not in order of the array, can that be?

 

How do I get the real/correct for each index (here in this example it would be "1")?

SNAG-0006.png

 

Thanks,

Stefan

1 ACCEPTED SOLUTION

Accepted Solutions

@cgru3eejc2 

 

Good catch. I was under wrong impression that you did not enable Concurrency. Good to see you the issue is resolved.

 

Regards

Krishna Rachakonda

If this reply helped you to solve the issue, please mark the post as Accepted SolutionMarking this post as Accepted Solution, will help many other users to use this post to solve same or similar issue without re-posting the issue in the group. Saves a lot of time for everyone.

View solution in original post

5 REPLIES 5
ManishJain
Solution Sage
Solution Sage

Hi @cgru3eejc2 ,

 

Are you using Loop inside loop (for each) to iterate over each array and each item inside that array ? If so you have to clear out the value at the first step before going to inner for each loop. This way you get the right value inside that inner loop.

 

Thanks

@cgru3eejc2 

 

You cannot increment variable value while setting it. 

 

Place a compose action before Set Variable. Insert the expression for increment of the variable in the compose action. 

 

Now, Set Variable to the output of the above Compose action.

 

Regards

Krishna Rachakonda

If this reply helped you to solve the issue, please mark the post as Accepted SolutionMarking this post as Accepted Solution, will help many other users to use this post to solve same or similar issue without re-posting the issue in the group. Saves a lot of time for everyone.
cgru3eejc2
Advocate IV
Advocate IV

Hi @ManishJain  and @rsaikrishna 

 

Thanks for your messages.

It's the only "loop" (for each). The increment on it's own counts up fine, so this is also not the problem.

 

I guess I found it - the for each is using parallelism (of course)...

I now changed the "Concurrency Control" in the for each settings to 1 and with that the for each index is equal to the variable which increments with each for each item loop.

Concurrency Control
By default, "For each" iterations run at the same time, or in parallel. To change the default limit, turn on this control, and select a limit. To run sequentially, select 1 as the limit.
 
Not sure if there is solution WITH using parallel running for each AND having the "correct" index run number.
 
Thanks all.
Stefan

Hi @cgru3eejc2 ,

 

If you have used concurrency control you have go with @rsaikrishna  method. 

 

If it resolves your issue please mark the solution as accepted.

 

Thanks

@cgru3eejc2 

 

Good catch. I was under wrong impression that you did not enable Concurrency. Good to see you the issue is resolved.

 

Regards

Krishna Rachakonda

If this reply helped you to solve the issue, please mark the post as Accepted SolutionMarking this post as Accepted Solution, will help many other users to use this post to solve same or similar issue without re-posting the issue in the group. Saves a lot of time for everyone.

View solution in original post

Helpful resources

Announcements
MPA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

V3_PVA CAmpaign Carousel.png

Community Challenge - Giveaways!

Participate in the Power Virtual Agents Community Challenge

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

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

R2 (Green) 768 x 460px.png

Microsoft Dynamics 365 & Power Platform User Professionals

DynamicsCon is a FREE, 4 half-day virtual learning experience for 11,000+ Microsoft Business Application users and professionals.

Top Solution Authors
Users online (2,599)