Power Platform:Power Automate – Get the next item in Apply to each loop
Business workflows have become easier since Power Automate Flows are with us. Power Automate lets us build complex functionalities easily. But, sometimes we need some functionality and if it is not readily available so we have to find workaround for that.
In one of the flow I was working on, I wanted to perform an operation on first item, if output of first item match with the condition then execute Yes block else execute No block i.e. to get next item and perform operation on that. So, let’s see how to do it!!
We are going to use following functions combinely:
- add(number1, number2) :- to carry out sum of integer
- skip([<collection>], <count>) :- it removes items from front of collection and returns the remaining collection of items. <count> is no. of items to remove from front of collection.
- first(‘<collection>’) or first([<collection>]) :- it returns first element of collection
- Initialize a variable of number, set its value to zero as this variable we are going to use as index of item.
- Use the following expression:
3. If you look at the expression, first of all add() is carried out, then skip() and finally first(). Have a look at following example:
// Collection is [25,40,30,54,87,9] // Initially index is set to 0 add(0,1) = 1 skip([25,40,30,54,87,9], 1) // 1 is output of add(0,1) //skip() will remove one element from the array or collection first([40,30,54,87,9]) // finally combining above functions first(skip([25,40,30,54,87,9],add(variables('index'),1))) // output is 40
4. For arrays it looks easy but this expression plays a great role when retrieving SP list item data.
5. If you want SP list item value for any particular column then you can use like below:
In my case, collection was nothing but the output of Get items action so I used value as collection and in place of <internal-column-name> I used AssignedTo/Email, so expression comes out to be.
Thanks for reading.
Please like, share, comment.