Skip to main content


 

Symptoms


When using the for-each wizard, K2 creates several data fields based on the item selected to be 'for-eached'. One of which is called YourItemRef Index Result. This "Index Result" is a Boolean value which stores whether or not there is another item in the collection following the current item.

K2 uses this true/false value to configure the default line rules for "no more items" and "next item". No More Items occurs when Index Result = False, and Next Item occurs when Index Result = True.

Therefore, when we reach the last item in the collection, the "next item" rule will not evaluate, so none of those operations will occur on the last list item, as there is no 'next' record. We will skip the last item.
 

Diagnoses


The issue was related to the Indexes not being reset to 0 after the item was deleted. The Index was still at 1, which would lead to missing out on the last item in the list.

Lets say we have a list of 5 items. We created an Item reference to each index in the list. Our items are as follows.
0 - Green
1 - Red
2 - Blue
3 - Yellow
4 - Orange

Now when we run through our loop, The Loop now only thinks there are 4 items, and starts at an index of 1. This leaves us with the last item not being deleted.


 

Resolution

We resolved the issue by adding a Set Data Fields after the item deletion in the For Each loop which resets the Index Data Field back to 0.




 
Be the first to reply!

Reply