Skip to main content

Notifications

Announcements

No record found.

Business Central forum
Suggested answer

Sample code to implement OnLookUp using AL

Posted on by

Hello:

I am new to AL coding. I like to implement OnLookUp within Purchaser Order Extension. This should allow lookUp using Description 2; similar to the default implementation of searching ITEMS by NO. and Description field. This is a learning exercise. I am just wondering whether any references or books are available that I can leverage to start learning this kind of implementation. There is not much within Docs.microsoft.com. DLP has good tutorials but falling short while providing quick references covering most of basic scenarios that I can leverage as reference. 

Appreciate any help on this... 

Categories:
  • mbharodia Profile Picture
    mbharodia on at
    RE: Sample code to implement OnLookUp using AL

    Thanks a lot for your help!

  • mbharodia Profile Picture
    mbharodia on at
    RE: Sample code to implement OnLookUp using AL

    Thanks for your help.

  • Oleksandr Shevchuk Profile Picture
    Oleksandr Shevchuk 175 on at
    RE: Sample code to implement OnLookUp using AL

    Currently, we cannot modify OnLookup trigger of the standard field in the pageextension. But we can add OnLookup trigger for our new field.

    So, you can do the following:

    1. Hide original Description 2 field on the Purchase Order page.
    2. Add the same Description 2 field on the page as your own and specify the unique field control name.
    3. Visually it will be the same field on the page, but now you can use OnLookup trigger.

    You can find a small example below, I did the same for the Export Protocol Code field on the Customer Bank Account Card page.

    pageextension 50000 "XXX Cust. Bank Account Card" extends "Customer Bank Account Card"
    {
        layout
        {
            modify("Export Protocol Code")
            {
                Visible = false;
            }
            addafter(IBAN)
            {
                field("XXX Export Protocol Code"; "Export Protocol Code")
                {
                    ApplicationArea = All;
    
                    trigger OnLookup(var Text: Text): Boolean
                    begin
                      // some code
                    end;
                }
            }
        }
    }


    pageextension 50054 "XXX Cust. Bank Account Card" extends "Customer Bank Account Card"
    {
    layout
    {
    modify("Export Protocol Code")
    {
    Visible = false;
    }
    addafter(IBAN)
    {
    field("XXX Export Protocol Code"; "Export Protocol Code")
    {
    ApplicationArea = All;

    trigger OnLookup(var Text: Text): Boolean
    begin
    // some code
    end;
    }
    }
    }
    }
  • Suggested answer
    Stefano Demiliani Profile Picture
    Stefano Demiliani 37,160 Most Valuable Professional on at
    RE: Sample code to implement OnLookUp using AL

    Currently you can only add code before or after the OnValidate trigger by using OnAfterValidate and OnBeforeValidate triggers:

    modify("Description 2")

    {

               trigger OnAfterValidate()

               begin

               end;

    }

    A good reference guide book:

    www.packtpub.com/.../dynamics-365-business-central-development-quick-start-guide

Helpful resources

Quick Links

Dynamics 365 Community Update – Sep 16th

Welcome to the next edition of the Community Platform Update. This is a weekly…

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,353 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,251 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans