cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
geneZebra 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
Dual Super User
Dual Super User

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

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
Dual Super User
Dual Super User

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

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
MBAS Gallery 2020

MBAS Gallery 2020

Watch Microsoft Business Applications Summit sessions on-demand.

firstImage

New Ranks and Rank Icons released on April 21!

The time has come: We are finally able to share more details on the brand-new ranks coming to the Power Automate Community!

firstImage

Now Live: Power Virtual Agents Community!

We are excited to announce the launch of Power Virtual Agents Community. Check it out now!

firstImage

New & Improved Power Automate Community Cookbook

We've updated and improved the layout and uploading format of the Power Automate Cookbook!

thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Community Summit North America

The top training and networking event across the globe for Microsoft Business Applications

Users online (8,868)