Notifications
Announcements
No record found.
I want to clear a collection class (declared at the class level) and reuse it. I suppose I can to this:
InventTransSet = new Set(Types::Int64)
That way it gets reset each time that i want to repopulate.
Do I need to worry about creating too many instances?
Thanks.
Hi brianmaric,
This does inadvertently create redundant instances. The values stored in the set can be traversed by using objects of type SetEnumerator, then removes elements from the set with Set.remove(Object) Method when you want to reset the collection class. Please check the MS document about X++ collection classes:
learn.microsoft.com/.../xpp-data-collection
Actually, I ended up doing this:
InventTransSet = null; InventTransSet = new Set(Types::Int64);
That should clear any existing instances should it not?
I had already tried this:
if(InventTransSet) { se = cInventTransSet.getEnumerator(); while (se.moveNext()) { recId = se.current(); InventTransSet.remove(recId); } }
But it throws an error;
I am supposing that this is because the enumerator is pointing to the very
element to be deleted. Perhaps I could wait for it to move to the next record and delete
the last one, but just setting it to null seems more simple.
looks like I need the interator if I want to just loop and delete
axpedia.blogspot.com/.../difference-between-enumerator-and.html
but this should work too:
agree?
Have you tried this SetIterator Class, and are you assigning value to the set repeatedly? Can you describe your business requirements in detail?
learn.microsoft.com/.../microsoft.dynamics.ax.xpp.setiterator
I can use either the iterator or just set the class to null.
Setting to null should get rid of the existing instance should it not?
(probably best to go with the iterator...it's cleaner)
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 659 Most Valuable Professional
André Arnaud de Cal... 533 Super User 2025 Season 2
Sohaib Cheema 289 User Group Leader