Top 5 This Week

Related Posts

Business Central: Creating Lookup, Drop-Down, and Option Lists (Single and Multi-select)

How to Create a Drop-Down, Lookup or Option list (Single and Multi select) in Business Central?

Have you ever needed to create a lookup field on one page in Dynamics 365 Business Central that pulls data from another table? In this post, I will cover the basic methods to create Lookup, Drop-Down, and Option lists. I hope you find this helpful.

Lookup List (Single Select) in BC

Solution: Create a lookup on the Sales Order page to display the customer name. For this demonstration, I used a variable on the Sales Order page, but you can also use an actual field.

Steps:

Use the RunModal method in the OnLookup() trigger.

AL Code Example: Lookup List (Single Select)

pageextension 50100 SalesOrderExt extends "Sales Order"
{
    layout
    {
        addafter("Sell-to Customer No.")
        {
            field(CustomerName; CustomerName)
            {
                Caption = 'Customer Name';
                ApplicationArea = All;

                trigger OnLookup(var Text: Text): Boolean
                var
                    CustomerRec: Record Customer;
                begin
                    CustomerRec.Reset();
                    if Page.RunModal(Page::"Customer List", CustomerRec) = Action::LookupOK then
                        CustomerName := CustomerRec.Name;
                end;
            }
        }
    }

    var
        CustomerName: Text[100];
}

Lookup List (Multi Select) in BC

Solution: Create a lookup on the Sales Order page to display a filter for items.

Steps:

Use the RunModal method and GetSelectionFilter in the OnLookup() trigger.

AL Code Example: Lookup List (Multi Select)

pageextension 50100 SalesOrderExt extends "Sales Order"
{
    layout
    {
        addafter("Sell-to Customer No.")
        {
            field(ItemFilter; ItemFilter)
            {
                Caption = 'Item Filter';
                ApplicationArea = All;

                trigger OnLookup(var Text: Text): Boolean
                var
                    ItemList: Page "Item List";
                begin
                    Clear(ItemFilter);
                    ItemList.LookupMode(true);
                    if ItemList.RunModal() = Action::LookupOK then begin
                        Text += ItemList.GetSelectionFilter();
                        exit(true);
                    end else
                        exit(false);
                end;
            }
        }
    }

    var
        ItemFilter: Text[100];
}

Drop-Down List in BC

Solution: Create a Drop-Down list on the Purchase Order page to display the vendor number and vendor name. For this demonstration, I used a variable on the Purchase Order page, but you can also use an actual field.

Steps:

Use the TableRelation property.

AL Code Example: Drop-Down List

// Table Extension: Add a new field to Purchase Line
tableextension 50100 PurchaseLineExt extends "Purchase Line"
{
    fields
    {
        field(50100; VendorSelection; Code[20])
        {
            Caption = 'Vendor Selection';
            DataClassification = ToBeClassified;
            
            TableRelation = Vendor."No.";
        }
    }
}

// Page Extension: Add the new field to Purchase Order page
pageextension 50100 PurchaseOrderExt extends "Purchase Order"
{
    layout
    {
        addafter("Buy-from Vendor No.")
        {
            field(VendorSelection; Rec.VendorSelection)
            {
                ApplicationArea = All;

                trigger OnLookup(var Text: Text): Boolean
                var
                    VendorRec: Record Vendor;
                begin
                    Clear(VendorRec);
                    if PAGE.RunModal(PAGE::"Vendor List", VendorRec) = Action::LookupOK then
                    begin
                        Rec.VendorSelection := VendorRec."No.";
                        Rec.Modify(true);
                        exit(true);
                    end
                    else
                        exit(false);
                end;
            }
        }
    }
}

Option List (Enum) in BC

Solution: Create a Drop-Down list on the Employee page to show the employee status.

Steps:

Create a new Enum type object and set values. Enums are lists consisting of named constants and can be used as table fields, local and global variables, and parameters. Enums replace the old Option data type, so create a new Enum instead of an Option during development.
Use the Enum object in a Page or Table.

AL Code Example: Option List (Enum)

enum 50100 EmployeeStatus
{
    value(0; "Active")
    {
        Caption = 'Active';
    }
    value(1; "Inactive")
    {
        Caption = 'Inactive';
    }
    value(2; "On Leave")
    {
        Caption = 'On Leave';
    }
}

I hope this guide helps you create Lookup, Drop-Down, and Option lists in Dynamics 365 Business Central. Thank you for reading.

Related Contents

Learn NAV Programming Language : C/AL

Making Fields Mandatory in Dynamics 365 Business Central

VScode Auto Save : D365 Business Central

Jubel
Jubelhttps://www.navisionplanet.com
Jubel Thomas Joy, a 16+ year Microsoft Dynamics 365 Business Central/NAV/Navision expert, founded "Navision Planet" in 2009. Certified in Business Central , D365 - Commerce and many more. He blogs on the latest updates and various modules of Business Central & LS Central, showcasing expertise in SQL, Microsoft Power Platforms, and over 150 organizations of work experience.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Popular Articles