web
You’re offline. This is a read only version of the page.
close
Skip to main content
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)
  • Rhushikesh R Profile Picture
    758 on at
    RE: Select minimum value from container through X++ code

    Thank you Nikolaos, that works perfectly :)

  • ergun sahin Profile Picture
    8,824 Moderator on at
    RE: Select minimum value from container through X++ code

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

  • Suggested answer
    ergun sahin Profile Picture
    8,824 Moderator on at
    RE: Select minimum value from container through X++ code

    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

  • Verified answer
    nmaenpaa Profile Picture
    101,160 Moderator on at
    RE: Select minimum value from container through X++ code

    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()));
        }

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > Supply chain | Supply Chain Management, Commerce

#1
CA Neeraj Kumar Profile Picture

CA Neeraj Kumar 1,011

#2
André Arnaud de Calavon Profile Picture

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

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 215 Most Valuable Professional

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans