I am new to outsystems I get "List was redefined while being iterated" error
I am appendig text values in foreach
Hi take a look following post
https://www.outsystems.com/forums/discussion/89835/list-was-redefined-while-being-iterated/
thank you
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.
it was resolved thank you Sir
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
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.
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
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.