ListRemove - Getting "List is being iterated, remove is not allowed" Error
Application Type
Reactive
Service Studio Version
11.10.20 (Build 41551)

Hi,

I'm trying to remove an entry from a list using ListRemove. UpdatedList is the list that I need entry to be removed from. As suggested in the forum (for other similar questions), I copied UpdatedList to a LocalList before the loop. And in the ListRemove, I am trying to remove the entry from the LocalList (with Position: UpdatedList.CurrentRowNumber). But I am getting "List is being iterated, remove is not allowed". What am I doing wrong?

Thanks

mvp_badge
MVP
Solution

Hello there Kat,

Hope you're doing well.


I would like to suggest another approach: you may use ListIndexOf System action in order to get the position of the element that satisfies the condition, which is the one you want to remove from the list:

After that, you should be able to use ListRemove, using that resulting position.

This way will allow you to avoid the loop and you won't need the extra local variable. You just need to use ListIndexOf and ListRemove actions :)


Hope that this helps you!


Kind regards,

Rui Barradas

Thanks a lot Rui, this works fine for my requirement. Appreciate your help.

Hi Kat,


In your solution, you are trying to assign the LocalList to the UpdatedList after you remove the item from the LocalList. That will try to override the UpdatedList which it is still considered as in the loop domain. Because the execution is still expect to close the loop after the assignment.

You can use Rui's answer which is the best for this case, or if you want to maintain you code, you can assign the UpdatedList.CurrentRowNumber  to a local variable when you find the item, then return the connection to the loop block instead of removing or updating the UpdatedList, and after that (now we are outside the loop domain) you can use the RemoveList action directly on the UpdatedList itself.


Regards,

Hasan

Thanks Hasan, now I understand the meaning of this error. ListRemove needs the loop to be closed.

mvp_badge
MVP
Solution

Hello there Kat,

Hope you're doing well.


I would like to suggest another approach: you may use ListIndexOf System action in order to get the position of the element that satisfies the condition, which is the one you want to remove from the list:

After that, you should be able to use ListRemove, using that resulting position.

This way will allow you to avoid the loop and you won't need the extra local variable. You just need to use ListIndexOf and ListRemove actions :)


Hope that this helps you!


Kind regards,

Rui Barradas

Thanks a lot Rui, this works fine for my requirement. Appreciate your help.

Hi Kat,


In your solution, you are trying to assign the LocalList to the UpdatedList after you remove the item from the LocalList. That will try to override the UpdatedList which it is still considered as in the loop domain. Because the execution is still expect to close the loop after the assignment.

You can use Rui's answer which is the best for this case, or if you want to maintain you code, you can assign the UpdatedList.CurrentRowNumber  to a local variable when you find the item, then return the connection to the loop block instead of removing or updating the UpdatedList, and after that (now we are outside the loop domain) you can use the RemoveList action directly on the UpdatedList itself.


Regards,

Hasan

Thanks Hasan, now I understand the meaning of this error. ListRemove needs the loop to be closed.

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