Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Answered

Can I turn a dictionary into two separate columns for a report in AL?

(0) ShareShare
ReportReport
Posted on by 479

Say I have a dictionary: { 'a':0, 'b':2, 'c':3 }. Can this be turned into two columns where one column are the keys, and the values for the other?
column(chars; chars){}
column(ints; ints){}

  • Verified answer
    YUN ZHU Profile Picture
    85,455 Super User 2025 Season 1 on at
    RE: Can I turn a dictionary into two separate columns for a report in AL?

    Hi, 'm not sure what your specific needs are, but here's a simple example that hopefully will give you some hints.

    pastedimage1654821405706v1.png

    page 50100 TestPageForDictionary
    {
        Caption = 'Test Page For Dictionary';
        PageType = List;
        UsageCategory = Lists;
        ApplicationArea = All;
        Editable = false;
        SourceTable = TestTableForDictionary;
    
        layout
        {
            area(Content)
            {
                repeater(Group)
                {
                    field(DictionaryKey; Rec.DictionaryKey)
                    {
                        ApplicationArea = All;
                    }
                    field(DictionaryValue; Rec.DictionaryValue)
                    {
                        ApplicationArea = All;
                    }
                }
            }
        }
    
        trigger OnOpenPage()
        begin
            InsertColumns();
        end;
    
        local procedure InsertColumns()
        var
            Dict: Dictionary of [Text, Integer];
            KeyText: Text;
            IntValue: Integer;
        begin
            Dict.Add('a', 0);
            Dict.Add('b', 2);
            Dict.Add('c', 3);
            foreach KeyText in Dict.Keys do begin
                Rec.Init();
                Rec.DictionaryKey := KeyText;
                Rec.DictionaryValue := Format(Dict.Get(KeyText));
                Rec.Insert();
            end;
        end;
    }
    
    
    table 50100 TestTableForDictionary
    {
        DataClassification = CustomerContent;
    
        fields
        {
            field(1; DictionaryKey; Text[50])
            {
                DataClassification = CustomerContent;
    
            }
            field(2; DictionaryValue; Text[50])
            {
                DataClassification = CustomerContent;
    
            }
        }
    
        keys
        {
            key(Key1; DictionaryKey)
            {
                Clustered = true;
            }
        }
    }

    Thanks.

    ZHU

  • jdrco Profile Picture
    479 on at
    RE: Can I turn a dictionary into two separate columns for a report in AL?

    HI yzhums , I am now in the process of trying to insert the keys and values into two columns. Not sure how to go about that.

  • Suggested answer
    YUN ZHU Profile Picture
    85,455 Super User 2025 Season 1 on at
    RE: Can I turn a dictionary into two separate columns for a report in AL?

    Hi, you can try to use Foreach method.

    Using this method you can get the key and value separately. Then insert them into the columns you want to use.

    For example:

    pastedimage1654737815516v1.png

    pageextension 50100 MyExtension extends "Customer List"
    {
        trigger OnOpenPage()
        begin
            Test();
        end;
    
        local procedure Test()
        var
            Dict: Dictionary of [Text, Integer];
            KeyText: Text;
            IntValue: Integer;
        begin
            Dict.Add('a', 0);
            Dict.Add('b', 2);
            Dict.Add('c', 3);
            foreach KeyText in Dict.Keys do begin
                Message(Format(KeyText));
                Message(Format(Dict.Get(KeyText)));
            end;
        end;
    }

    Hope this helps.

    Thanks.

    ZHU

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

Ramesh Kumar – Community Spotlight

We are honored to recognize Ramesh Kumar as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

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

#1
Sohail Ahmed Profile Picture

Sohail Ahmed 2,655

#2
Mansi Soni Profile Picture

Mansi Soni 1,574

#3
YUN ZHU Profile Picture

YUN ZHU 1,453 Super User 2025 Season 1

Featured topics

Product updates

Dynamics 365 release plans