Creating Loop Ups and Drill Downs in Microsoft Dynamics Business Central AL - Muhammad-Ali-Mughal/Microsoft-Dynamics-BC-AL-Extension GitHub Wiki

Creating LoopUps and DrillDowns in BC AL

Both of these help users to select a pre-entered record of a table and on the basis of that record it also allows you to get the data of fields of that record. You'll see a lot of them in Business Central and after selection you'll find automatic data assigning into the fields. Loop Ups and Drill Downs are very useful for functionals and users.

DrillDowns in AL

These are very simple to define because you just have to create a table relation of the field in the table in which you want to get the Drill Down.

field(110; "Vendor No"; Code[20])
        {
            TableRelation = Vendor;
            DataClassification = CustomerContent;
        }

This is a field of a table and has a relation with Vendor table of the system. When a record will be selected through Drill Down "Vendor No" field will be validated.

LookUps in AL

LookUp is a little different from DrillDown because LookUp takes all the area of the page to display records of the table. LookUp is defined in page in the OnLookUp trigger:

field("Customer No."; Rec."Customer No.")
                {
                    ApplicationArea = All;
                    trigger OnLookup(var text: Text): Boolean
                    var
                        Customer: Record Customer;
                    begin
                        if Page.RunModal(Page::"Customer Lookup", "Customer") = Action::LookupOK then begin
                            Rec."Customer No." := Customer.GetCustNo(Customer.Name);
                            Rec.Name := Customer.Name;
                            Rec."Name 2" := Customer."Name 2";
                            Rec.Address := Customer.Address;
                            Rec.Email := Customer."E-Mail";
                            Rec."Post Code" := Customer."Post Code";
                            Rec.Country := Customer.County;
                            Rec.State := Customer."State Inscription";
                            Rec."Shipment Method Code" := Customer."Shipment Method Code";
                            Rec."Payment Method Code" := Customer."Payment Method Code";
                        end;


                    end;

                }

Here, OnLookUp trigger is defined as its definition and a Customer is taken as variable and initialized by Record Customer. Inside trigger, when the page runs the LookUp of Page "Customer Lookup" and table "Customer" and after selecting a record, user press OK button of lookup (Action::LookupOK) then all the field values of current record are assigned the values of selected Customer record.

LookUpPageId and DrillDownPageId Properties in Tables

Both of these properties are defined in tables. These properties define the page which will be used for LookUps and DrillDowns of the records of the table. These pages should be list pages or listpart pages.

Usage:

table 50106 "Dispute Status"
{
    DataClassification = CustomerContent;
    DrillDownPageId = "Dispute Status";
    LookupPageId = "Dispute Status";

    fields
    {
        field(10; "Provenance Disputed"; Enum "Provenance Disputed")
        {
            DataClassification = CustomerContent;
        }
        field(20; "Dispute Status Code"; Code[20])
        {
            DataClassification = CustomerContent;
        }
        field(30; "Description Status Dispute"; Text[100])
        {
            DataClassification = CustomerContent;
        }
    }

    keys
    {
        key(PK; "Dispute Status Code")
        {
            Clustered = true;
        }
    }
}