Skip to main content

Notifications

Announcements

No record found.

Business Central forum

Sample code to implement OnLookUp using AL

(0) ShareShare
ReportReport
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,162 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

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

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

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

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,642 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,371 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans