Skip to main content

Notifications

Finance | Project Operations, Human Resources, ...
Suggested answer

Collection Class Reset

(0) ShareShare
ReportReport
Posted on by

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.

  • brianmaric Profile Picture
    brianmaric on at
    RE: Collection Class Reset

    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)

  • Suggested answer
    huijij Profile Picture
    huijij 19,811 on at
    RE: Collection Class Reset

    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

  • brianmaric Profile Picture
    brianmaric on at
    RE: Collection Class Reset

    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?

  • brianmaric Profile Picture
    brianmaric on at
    RE: Collection Class Reset

    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;

    pastedimage1681192524813v1.png

    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.

  • huijij Profile Picture
    huijij 19,811 on at
    RE: Collection Class Reset

    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

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.

Helpful resources

Quick Links

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,969 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,842 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans