208
Views
10
Comments
ERROR: List was redefined while being iterated.
Question
Application Type
Reactive

I am displaying a table, whose data is coming from an aggregate.

and on the OnAfterFetch of that same aggregate, i applied a loop.

Images are below:

Due to which i am facing this error, while SEARCHING and SORTING.

Please help me with the problem.

A solution oml would be a great help.


2025-04-16 10-58-33
Priyanka Babar

Dear @Mohd Anees Mansoori 

Instead of refreshing aggregate you can assign aggregate value to a List (list of subtask) and then in the iterations use list.

Regards

Priyanka

2025-10-18 11-13-53
Ramesh subramanian

Hi Mohd Anees Mansoori,

https://www.outsystems.com/forums/discussion/78933/how-to-avoid-the-list-was-redefined-while-being-iterated-error/

I already answered the same question in this link. 


Thanks,


Ramesh

2021-12-22 12-25-29
Vaishnavi Bokade

Hello @Mohd Anees Mansoori ,

                    I am providing some references you can visit and check it. I hope it will work for you.

Link 1 : https://www.outsystems.com/forums/discussion/78933/how-to-avoid-the-list-was-redefined-while-being-iterated-error/

Link 2 : https://www.outsystems.com/forums/discussion/41600/called-enditeration-while-the-list-was-not-being-iterated/

Link 3 : https://www.outsystems.com/forums/discussion/70336/listremove-getting-list-is-being-iterated-remove-is-not-allowed-error/


Thanks 

Vaishnavi Bokade

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

Hi Mohd,

If you iterate over a list with a For Each, you cannot change the content of the list. So no ListAppend, ListDelete etc., and also no refreshing the aggregate that is the source of the list. Think of how this should work functionally, you are half way the list, then you refresh, and now the data is totally different - how can it continue looping?

2025-09-21 06-51-05
Mohd Anees Mansoori

I was not refreshing the aggregate that is the source of the list, that is another aggregate.

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

Sorry for the late reply, I was on holiday.

If you are refreshing a different query, debug to determine exactly when this error occurs. Is it right on the second iteration? What if you do not refresh the query (temporarily disable it), do you still get the error? If not, does the second query have an On After Fetch that does something with the original query's output? Etc.

2023-03-16 04-58-56
Ashish Lonkar

Hi Mohd Anees Mansoori, 

Before iterating the list you should create its local copy and then iterate over that. you cannot iterate and modify at the same time using forEach. you try If and Assign to try Iterate the list maybe that might allow u to do it.

This is actually an classical case of ConcurrentModificationException.

Thanks AWL!

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

Hi Ashish,

That is bad advice. You don't go creating copies of lists just as a workaround for problems you do not understand. That'll lead to bad code, and your gain 0 understanding.

As for your remark about not being able to iterate and modify, that has been discussed above already at length, please read the replies before you answer!

UserImage.jpg
Tahil Mirza

Hi Kilian,

Do you have any solution on how we can iterate a list that can be modified while iterating?


regards.

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

The only way to do that is direct indexing of the List, and adjusting the running index for an insert or delete. Note that "modifying" here means inserting an element or deleting an element, modifying the attributes of the structure that's in the list is fine.

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