101
Views
12
Comments
Solved
I am new to outsystems I get "List was redefined while being iterated" error
Question

I am new to outsystems I get "List was redefined while being iterated" error 

I am appendig text values in foreach 

UserImage.jpg
Meharees Shamsudeen

thank you

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP
Solution

Hi Maharees,

Not only not possible in OutSystems, but also not in e.g. C# or Java. If you iterate (i.e. use a For Each) over a list, you cannot modify that list. That means you cannot delete records, or add new records. You can change the value of attributes of the records, but the number of elements in the list can't be changed.

As others have already commented, duplicating the list first may be a solution, though if you just want to add items, add those items to a seperate list, and then ListAppendAll that seperate list to the original after iterating. Another possibility is to create an ad-hoc loop, using an index variable, and index the list records directly instead of using the Current.

However, in general you'll have to ask yourself what you want to achieve, as trying to manipulate a list you are also looping over might indicate (though not necessarily is) a flaw in the way you've structured your code.

UserImage.jpg
Meharees Shamsudeen

it was resolved thank you Sir

2025-01-23 05-58-39
Jamal Mohammed
Solution
UserImage.jpg
Meharees Shamsudeen

thank you

2025-08-03 07-20-35
Mythily - EONE

Hi,

You might be assigning the value for the same list that you have been iterating.

If possible send the Screenshot of your logic, it helps to correct the code.

Thanks

UserImage.jpg
Meharees Shamsudeen

thank you

2023-11-22 10-51-50
Jozy Sohail

Hi,

This usually happens when you try to manipulate the same list you  are iterating.

Try avoiding these kind of scenarios.

Also, if possible please share the OML or explain your problem in detail so we can help.

Thanks.

UserImage.jpg
Meharees Shamsudeen

thank you

2024-05-08 06-29-37
Prince Aadil Khan Panwar

Hi Meharees Shamsudeen,

I understood your condition. you can never append the list which you were using in Loop. if you want to do this approach do one thing. make a copy of the list variable. in to the another same type of variable and just append in the copied List variable.

Regards,

Prince

UserImage.jpg
Meharees Shamsudeen

thank you

2025-08-03 07-20-35
Mythily - EONE

Hi,

1) Use List Duplicate for the list you use,

2) For Each- List duplicate

3) to get the position of item to append

4)with index position, assign value.

Thanks

UserImage.jpg
Meharees Shamsudeen

thank you

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP
Solution

Hi Maharees,

Not only not possible in OutSystems, but also not in e.g. C# or Java. If you iterate (i.e. use a For Each) over a list, you cannot modify that list. That means you cannot delete records, or add new records. You can change the value of attributes of the records, but the number of elements in the list can't be changed.

As others have already commented, duplicating the list first may be a solution, though if you just want to add items, add those items to a seperate list, and then ListAppendAll that seperate list to the original after iterating. Another possibility is to create an ad-hoc loop, using an index variable, and index the list records directly instead of using the Current.

However, in general you'll have to ask yourself what you want to achieve, as trying to manipulate a list you are also looping over might indicate (though not necessarily is) a flaw in the way you've structured your code.

UserImage.jpg
Meharees Shamsudeen

it was resolved thank you Sir

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