Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Business Central forum

Modern pattern for Lookup showing Name and Not Code in new Page Extension

(0) ShareShare
ReportReport
Posted on by

There seems to be a lot of old material around, but none which makes it absolutely clear how to obtain the new best practice of showing a field with both the code and name of a vendor, customer or contact and supporting a lookup from either field. 

I tried to look into the source code on the Vendor and Sales Order page, but enough detail is hidden in the definition that I can't quite nail it.

I have a new table and page called Container Entry. These need to refer to both a Vendor and Customer.

Looking at some old recommendations I tried to add to the OnLookup trigger event of the Vendor Name field, but it doesn't work. Code below.

Here is an excerpt from the Table Definition.

  field(50182; "No."; Code[20])
        {
            DataClassification = CustomerContent;
            trigger OnValidate()

            BEGIN
                IF "No." <> xRec."No." THEN BEGIN
                    PurchaseSetup.GET;
                    NoSeriesMgt.TestManual(PurchaseSetup."Order Nos.");
                    "No. Series" := '';
                    NoSeriesMgt.SetSeries("No.");

                END;
            end;
        }
        field(50184; "No. Series"; Code[20])
        {
            DataClassification = CustomerContent;
            TableRelation = "No. Series";
            ValidateTableRelation = true;

        }
        field(50204; "Vendor No."; Code[20])
        {
            DataClassification = CustomerContent;
            TableRelation = Vendor;
            ValidateTableRelation = true;


        }
        field(50213; "Vendor Name"; Text[100])
        {
            Caption = 'Vendor Name';
            TableRelation = Vendor.Name;


            trigger OnValidate()

            var
                VendorRec: Record Vendor;
            begin

                "Vendor No." := VendorRec.GetVendorNo("Vendor Name");
                
            end;
           
        }

Here is an excerpt from the page definition:

                    field(Shipper; "Vendor No.")
                    {
                        ApplicationArea = All;


                    }
                    field("Vendor Name"; "Vendor Name")
                    {
                        ApplicationArea = All;
                        TableRelation = Vendor.Name;
                        Lookup = true;
                        LookupPageId = "Vendor List";


                    }

Here is what it looks like.

The vendor number drop down works fine. However, there is no active lookup on the Vendor Name. Clicking it does nothing and I'm not sure how it will then update the
Vendor Number field at the same time. I have used a code unit on the function to do that.

6052.Capture.PNG

Categories:
  • Suggested answer
    Rufus Profile Picture
    on at
    RE: Modern pattern for Lookup showing Name and Not Code in new Page Extension

    Thanks - so simple and works perfectly.

  • Verified answer
    I Gusti Made Ari Profile Picture
    3,594 on at
    RE: Modern pattern for Lookup showing Name and Not Code in new Page Extension

    Please change your field  properties to below :

           field(50204; "Vendor No."; Code[20])

           {

               DataClassification = CustomerContent;

               TableRelation = Vendor;

               ValidateTableRelation = true;

               trigger OnValidate()

               var

                   VendorRec: Record Vendor;

               begin

                   VendorRec.Get("Vendor No.");

                   "Vendor Name" := VendorRec."Name";

               end;

           }

      field(50213; "Vendor Name"; Text[50])

           {

               Caption = 'Vendor Name';

               TableRelation = Vendor;

               ValidateTableRelation = false;

              trigger OnValidate()

               var

                   VendorRec: Record Vendor;

               begin

                   VALIDATE("Vendor No.",VendorRec.GetVendorNo("Vendor Name"));

               end;

            }

    On the page extension you can remove the table relation and lookup properties.

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 > Business Central forum

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans