cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Resolver II
Resolver II

how to peek at next item in an apply to all loop

I am looking to find a simple way to see the "next" item in an apply to all loop I use to iterate through a sorted list that I get from the List rows in table action.

 

My overall log is:

1) Get table that has user's column sorted by user

2) Apply to each item in the table

2.1) append value to a emailBody string

2.2) if user from next item in the loop is (different than current item) or (empty), send the email; Otherwise, do nothing

2.3) end loop

 

My problem is I can't seem to find an easy way to get the next item in the loop. I have worked on several variants of the loop with similar logic but it either clutters up the flow (with too many checks/updates for if previous = current logic) or introduces undo inefficiencies by using a filter that internally loops through the table on each call within the outer loop.

 

My goal is to build the list as I iterate through the list but keep the logic easy to follow. The logic to loop up and send an email could be a little invloved since I need to handle invalid user found and do lookups for a back up email address so if I can block out this code with a simple if statement, it would be easier to maintain and follow. maintaining a previous item variable seems to cloud up the logic. 

 

If there are any suggestion on how to look at the next item in the loop, please share. I noticed there is a "skip()" function that may help, but I do not know how to pass in the index value of an "apply to" loop.

 

Sorry for the long explaination. I am hoping there is an easy answer or technique here.

 

Thanks

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Dual Super User II
Dual Super User II

Hi @geneZebra 

 

Before for loop, initialize a variable of type number and set its value to 0 (this will be used to drive the index of the item)

 

Next within the loop

the expression item() will give you context to the current running item

If you need to read  a particular property you can use

item()?['columnname'] to get its value

 

Now to peek into next item

You can use the following expression

 

first(skip(dynamiccontentcollection,add(variables('counter'),1)))
where dynamiccontentcollection - is the dynamic content value of the collection being looped
This will give you the next item
If you want to read a particular property of next item
use expression first(skip(dynamiccontentcollection,add(variables('counter'),1)))?['columnname']
 

Regards,

Reza Dorrani

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

View solution in original post

1 REPLY 1
Highlighted
Dual Super User II
Dual Super User II

Hi @geneZebra 

 

Before for loop, initialize a variable of type number and set its value to 0 (this will be used to drive the index of the item)

 

Next within the loop

the expression item() will give you context to the current running item

If you need to read  a particular property you can use

item()?['columnname'] to get its value

 

Now to peek into next item

You can use the following expression

 

first(skip(dynamiccontentcollection,add(variables('counter'),1)))
where dynamiccontentcollection - is the dynamic content value of the collection being looped
This will give you the next item
If you want to read a particular property of next item
use expression first(skip(dynamiccontentcollection,add(variables('counter'),1)))?['columnname']
 

Regards,

Reza Dorrani

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

View solution in original post

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

Power Platform ISV Studio

Power Platform ISV Studio

ISV Studio is designed to become the go-to Power Platform destination for ISV’s to monitor & manage published applications.

Top Solution Authors
Top Kudoed Authors
Users online (7,355)