25
Views
3
Comments
Solved
For Each Start Index default value not always zero
Question
Application Type
Reactive
Service Studio Version
11.55.21 (Build 64159)

Hi,

Today I found out that the For Each Start Index default value is not always zero. According to the documentation of the For Each Start Index it should be zero. But in reality it looks more like it's based on the Start Index of your list you're trying to iterate on. 

Because in my case I have a front-end screen with a table that is filled with data from my aggregate. I do directly changes on the records of the aggregate based on the user inputs in the table. So the CurrentRowNumber of the aggregate changes. At the end I have a part where I save all the changes using a button and at the start of the save action flow I do a List Filter on the aggregate data and noticed that the CurrentRowNumber of the List Filter is not zero but has something to do with the CurrentRowNumber of the aggregate. Now, right after the List Filter I do a For Each loop and use the result of the List Filter in it. When I start the debugger and debug the first For Each iteration I can see that the CurrentRowNumber of the List Filter is still not zero while I have not set a value in the For Each Start Index. So the default value should be applied which according to the documentation is zero.

Is this normal behaviour for a List Filter to take over the CurrentRowNumber from a different list or in my case an aggregate? Is it normal for the For Each loop to not apply the default value of zero on the List Filter that has a CurrentRowNumber of something different than zero? And is the documentation about the default value of the For Each correct?

2023-06-13 12-29-43
Sakthivel P
Solution

Hi @Bo Menick,

  • Yes, it's normal for the CurrentRowNumber to persist from the Aggregate even after filtering.

  • Yes, For Each correctly defaults Start Index to 0, but that doesn’t reset CurrentRowNumber of the list items.

  • Yes, the documentation is correct but incomplete, as it doesn't explain the retention of row numbers across list operations. 

UserImage.jpg
Bo Menick

Hi Sakthivel,

Thank you for the information.

So now I'm wondering if it's possible to reset the CurrentRowNumber of the list or aggregate to zero. Or do I have to create a for loop using an if-statement and a local integer variable?

2023-06-13 12-29-43
Sakthivel P


Clone the Filtered List to new list using ListAppendAll action this reset the CurrentRowNumber. Make sure to clear the new list at start of save action.

Suggestion:

When building logic to save modified rows from a table, consider adding a WasEdited boolean flag to each record and only process records where WasEdited = True. Then work on a filtered cloned list of these rows.

Thanks,

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.