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 :
Supply chain | Supply Chain Management, Commerce
Answered

Select minimum value from container through X++ code

(0) ShareShare
ReportReport
Posted on by 758

Hi Experts,

If I have one container as below,

[100, 25, 30, 200]

And I want to select minimum value from it.

How can I achieve the same through X++ code? Please suggest.

And if not container, what functionality I can use to store the set of values and get the minimum from it at the end of while loop.

I have the same question (0)
  • Verified answer
    nmaenpaa Profile Picture
    101,160 Moderator on at

    You can use a Set, they sort themselves. This example prints all your values in ascending order. So the first value that you get out of the SetEnumerator is the smallest one.

        Set mySet = new Set(Types::Integer);
        SetEnumerator setEnum;
        
        mySet.add(100);
        mySet.add(25);
        mySet.add(30);
        mySet.add(200);
        
        setEnum = mySet.getEnumerator();
        
        while (setEnum.moveNext())
        {
            info(strFmt("%1", setEnum.current()));
        }

  • Suggested answer
    ergun sahin Profile Picture
    8,826 Moderator on at

    You can get min value with;

    min(100, 25, 30, 200)

    I don't remember that container and other similar types have a method that gives a direct min. Of course, you can find the smallest value by loop.

    If you ask me, the easiest is insert records into tmp table and select minOf(value), or order by value Asc and get firstOnly

  • ergun sahin Profile Picture
    8,826 Moderator on at

    I hadn't noticed that SetEnumerator sorts the values in ascending order

  • Rhushikesh R Profile Picture
    758 on at

    Thank you Nikolaos, that works perfectly :)

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 > Supply chain | Supply Chain Management, Commerce

#1
Laurens vd Tang Profile Picture

Laurens vd Tang 298 Super User 2025 Season 2

#2
Siv Sagar Profile Picture

Siv Sagar 179 Super User 2025 Season 2

#3
André Arnaud de Calavon Profile Picture

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

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans