462
Views
1
Comments
Solved
How to avoid the "list was redefined while being iterated" error



Hello,

I am doing this AfterFetch of an aggregate to calculate the four last attributes of the right structure (the attributes selected are the information of the aggregate). The list where i append the information is the List that i use to display the info on the popup and on the table shown.

Because of this, i am currently with the error above.

How can I avoid this? I already try to duplicate the aggregate info, but i was not able to do that.

Some help?

2021-06-02 20-50-04
Márcio Carvalho
Solution

You need to use an auxiliary variable to make your changes.

You can use the original list to loop or the aux, but you cannot loop a list and update at the same time the same list.

  1. Create aux
  2. At the beginning or before the loop copy everything from the original to the aux
  3. Use the aux or the original to loop and update/delete whatever you want with the aux/original, it cant be the same.
  4. after all the operations, you to get the output do an assign from the list that you use to do the changes to the list that will be the output.
Ps: if you want to change just one specific record you need to do a list index of to find the record and then update, but don't forget what I said about updating something on a list that you are looping.

Kind Regards,

Márcio

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