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.
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)
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
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:
InventTransSet = null; InventTransSet = new Set(Types::Int64);
agree?
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.
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:
André Arnaud de Cal...
291,969
Super User 2025 Season 1
Martin Dráb
230,842
Most Valuable Professional
nmaenpaa
101,156