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
Solved! Go to Solution.
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
Regards,
Reza Dorrani
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly
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
Regards,
Reza Dorrani
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly
Dive into the Power Platform stack with hands-on sessions and labs, virtually delivered to you by experts and community leaders.
Watch Nick Doelman's session from the 2020 Power Platform Community Conference on demand!
User | Count |
---|---|
12 | |
11 | |
7 | |
7 | |
6 |
User | Count |
---|---|
18 | |
17 | |
12 | |
10 | |
9 |