web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
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.

I have the same question (0)
  • huijij Profile Picture
    19,811 on at

    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

  • brianmaric Profile Picture
    on at

    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.

  • brianmaric Profile Picture
    on at

    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?

  • Suggested answer
    huijij Profile Picture
    19,811 on at

    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
    on at

    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.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 659 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 533 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 289 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans