Table of Contents
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