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.
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
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
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
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?
I was not refreshing the aggregate that is the source of the list, that is another aggregate.
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.
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!
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!
Hi Kilian,
Do you have any solution on how we can iterate a list that can be modified while iterating?
regards.
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.