Notifications
Announcements
No record found.
Hi in X++, is it possible to delete items while iterating through list and not causing error? I know it's doable in C# but not sure how x++ language handle it.
at the moment, I can't look for 365 but at 2012 for iterating a list you can use listIterator or listEmulator. ListIterator has delete method but emulator dont have such a method. In 2012 I don't use iterator (server/client side pointer problem) but I don't think 365 have this problem
https://docs.microsoft.com/en-us/dotnet/api/microsoft.dynamics.ax.xpp.listiterator
www.google.com/.../
Hi,
To remove objects from a list you need to use an iterator.
In X iterators require the developer to write a loop with calls to more() and next() to check if there are any elements left and make iterator advance to the next element.
list = new List(Types::String); list.addEnd('a'); list.addEnd('b'); list.addEnd('c'); list.addEnd('d'); iter = new ListIterator(list); while (iter.more()) { value = iter.value(); if (true) // check value { iter.delete(); } else { iter.next(); } } info(list.toString());
Either do a delete() or a next(). Not both. The same goes for maps and sets.
And by the way, if you want to do anything other than delete elements it’s highly recommended you use enumerators instead of iterators.
You can also consider alternative designs. For example, you can have a Set with all items and add items to be deleted to another Set. Then you'll use Set::difference() to create a set without deleted items:
Set remainingItems = Set::difference(allItems, deletedItems);
Hi Yvonne,
As the upstairs insight,Here is a link about the Iterator for deleting item in list:
Enumerator and Iterator
regards
Under review
Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.
As AI tools become more common, we’re introducing a Responsible AI Use…
We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…
These are the community rock stars!
Stay up to date on forum activity by subscribing.
Martin Dráb 664 Most Valuable Professional
André Arnaud de Cal... 522 Super User 2025 Season 2
Sohaib Cheema 303 User Group Leader