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

Announcements

No record found.

News and Announcements icon
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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

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

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 512 Super User 2026 Season 1

#2
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 386

#3
Adis Profile Picture

Adis 259 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans