Append is not a valid operation inside a StartIteration/EndIteration block.

Append is not a valid operation inside a StartIteration/EndIteration block.

  

Hello,

I am creating recordlist from the result of an aggregate. For that I am iterating through foreach loop of result set of an aggregate.

I am getting this error.

This is the logic 


Please advice.

Thanks and Regards,

Suraj Borade


Hi Suraj,

I am guessing you trying to append record in list which you are using in for-each loop.

If still problem not solved please attach oml.


Regards

SK


Hi Suraj,

If you are trying to append\remove a record in the same list you are iterating on it will give you error and this is because the length of the list has decided when you start the iteration .



Regards

-PJ-

Yeah, what Sashi and Pramod said. Mutating a list you're iterating over is not possible, for obvious reasons. What were you tring to do? I can't think of many use cases that would be in need for modifying a list you're iterating. If you do have a good use case, first ListDuplicate the list, then Append to the duplicated list.

Kilian Hekhuis wrote:

Yeah, what Sashi and Pramod said. Mutating a list you're iterating over is not possible, for obvious reasons. What were you tring to do? I can't think of many use cases that would be in need for modifying a list you're iterating. If you do have a good use case, first ListDuplicate the list, then Append to the duplicated list.

Hi Kilian,

When I a nested object , each level 1 list record has a level 2 list.

level 1 list

  Level  2 list


when i try to remove record in level 2 list while i am in level 1 list loop, the same error will still happen, i need to check the value in the level 1 list record first and then decide which record in level 2 list to remove, how i can do this?


Hi Linguo,

Next time, please start a new topic - this one is over two years old!

As for your question, I just did a test, and it is no problem to ListRemove an item of a List that's not being iterated over, even if that List is an Attribute of a List that's being iterated:

Note that this is purely a test, in an actual program I'd use ListIndexOf instead of the inner loop + If.