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 :
Small and medium business | Business Central, N...
Answered

get a unique collection of items

(0) ShareShare
ReportReport
Posted on by

Hi Everyone

I have a case in which I need distinct Values from a list.

The common approach to get a unique collection of items is to use a set. Sets are unordered collections of distinct objects.

Is there a set method in AL ? If not, what would be the common approach ?

Thank you very much for your answer.

I have the same question (0)
  • Verified answer
    Ashish0386 Profile Picture
    75 on at

    You can do it by writing some code

    Item.RESET;

    Item.SETCURRENTKEY("Name");

    IF item.FINDSET THEN REPEAT

    IF prevItemname = item.Name THEN

       Previtemname := item.Name;

    UNTIL(Item.NEXT=0);

    may be it can help

  • Verified answer
    Lars Lohndorf-Larsen Profile Picture
    Microsoft Employee on at

    +1 to Ashis' idea.

    I am not sure what a set is, but it sounds like a list which we have in BC, example:

    codeunit 50107 Test

    {

       trigger OnRun()

       begin

           customer.FindSet();

           repeat

               if not MyList.Contains(Customer.Name) then

                   MyList.Add(customer.Name);  

           until Customer.Next() = 0;

       end;

       var

           Customer: Record Customer;

           MyList: List of [text];

    }

    More about List datatype here:

    docs.microsoft.com/.../list-data-type

  • Sleina Profile Picture
    on at

    Thank you Ashish and Lars

    I actually used the List Type as follows:

    If ItemVariant.FindFirst() then begin

                               repeat

                                   Colorlist.add(ItemVariant.Farbe);

                               until ItemVariant.next = 0;

                           end;

                           //Check unique

                           For i := 1 to ColorList.Count do begin

                               ContainValue := ColorList.Get(i);

                               Result := IsUnique.Contains(ContainValue);

                               if Result = False then

                                   IsUnique.Add(ContainValue);

                           end;

    This worked, thank you both, now I know that I'm on the right way in order to get such values :)

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!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,140 Super User 2026 Season 1

#2
YUN ZHU Profile Picture

YUN ZHU 1,362 Super User 2026 Season 1

#3
AndrewThomas81 Profile Picture

AndrewThomas81 1,216

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans