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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

Sets

(1) ShareShare
ReportReport
Posted on by 556
Hi,

Is the code below considered as 2 while loops? how is the performance of using the 'in' method for Sets? and what does the 'in' do? doesn't it do a while loop somehow?
 while select table1
        where  table1.Id == _Id
            && table1.Id1 == _Id2
        {
            if(!_set.in(table1.RecId))
            {
            }
        }
 
I have the same question (0)
  • Suggested answer
    Martin Dráb Profile Picture
    240,061 Most Valuable Professional on at
    There is only one loop - the while select. What else wouldn't you consider a loop?
     
    The in() method of the Set class checks if a given value can be found in the set. Note that you can check the documentation to find the answer. Performance depends on the number of elements in the set, but it's very fast. The possible performance problem may be in the fact that your select gets records that you're interested in (because they aren't in the loop), but if there aren't many and it's not a performance-critical code, you probably don't need to worry about it too much.
     
    If you want to address it, you may use Query classes or SysDa to create the query. When doing so, you'll iterate all elements in the set and add a range for each of them.
  • DELDYN Profile Picture
    556 on at
    Hi Martin,
     
    You said the performance of "in" depends on number of elements. So if let's say there is 100 recIds in the Set, would it still be fast?
     
    I didn't get what you meant by "The possible performance problem may be in the fact that your select gets records that you're interested in (because they aren't in the loop)" ??
    My set contains line RecIds coming from an external system, so i'm looping through the actual table to see what line RecIds for a certain header are sent and what are not sent.
     
    And why did u suggest using a query?

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the June Top 10 Community Leaders

These are the community rock stars!

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

#1
André Arnaud de Calavon Profile Picture

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

#2
Subra Profile Picture

Subra 373

#3
Martin Dráb Profile Picture

Martin Dráb 251 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans