web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Suggested Answer

AL coding issues

(0) ShareShare
ReportReport
Posted on by 44

Hi All,

I'm having some problems (again) getting my code to work.

On my purchase invoice page, i have a column "code" which is the Code field from the Dimension Vale table.

I need that to auto populate a a table extension i created called Desc2. This is extension extends the Purchase Line table

I can select it manually, but i need it to auto populate.

Here's my code, can someone help show me where i went wrong?

AS always , thanks for your help.

Rajiv

tableextension 50134 "Desc 2" extends "Purchase Line"
{
    fields
    {
        field(50134; "Desc 2"; text[50])
        {
            DataClassification = ToBeClassified;
            Caption = 'Desc 2';
            TableRelation = "Dimension Value".Name where("Code" = field("Shortcut Dimension 1 Code"));
            ValidateTableRelation = false;
        }
    }
    local procedure OnValidate(var "Code": Record "Dimension Value")
    var
        "Desc 2": Record "Purchase Line";
    begin
        if "Code".get(Rec."Shortcut Dimension 1 Code") then begin
            "Desc 2" := "Desc 2"
        end;
    end;


}


pageextension 50134 "Desc 2 " extends "Purch. Invoice Subform"
{
    layout
    {
        addafter("Description 2")
        {
            field("Desc 2"; Rec."Desc 2")
            {
                Caption = 'Desc 2';
                ApplicationArea = all;
            }
        }
    }
}

  • Suggested answer
    YUN ZHU Profile Picture
    103,712 Super User 2026 Season 2 on at

    Hi, This looks like a problem with your OnValidate trigger usage.

    I didn't find the Code field in your source code. (Maybe in Purchase Header?)

    You need to find the Code field and add the OnValidate Trigger in this field, not a local OnValidate procedure. 

    https://docs.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/triggers-auto/field/devenv-onvalidate-field-trigger

    If this is a standard field, you need to use the OnAfterValidate trigger in your TableExtension.

    pastedimage1653607562229v1.png

    Hope this helps.

    Thanks.

    ZHU

  • rajivsewsarran Profile Picture
    44 on at

    Hi ZHU,

    thanks as always for you response.

    I've adjusted the code and had no luck

    pastedimage1653617102263v1.png

    This is the purchase line

    the entity code is "Shortcut dimension 1" i need that to be able to auto populate "Desc2", which is the table extension i created above.

    I was using the "Code" field from the dimension value table, but i realize that this may not be suitable.

    I dont get the "OnValidate" Option coming up for my trigger.

    Below is the adjustment i made - i can select the correct value manually

    tableextension 50134 "Desc 2" extends "Purchase Line"
    {
        fields
        {
            field(50134; "Desc 2"; text[50])
            {
                DataClassification = ToBeClassified;
                Caption = 'Desc 2';
                TableRelation = "Dimension Value".Name where("Code" = field("Shortcut Dimension 1 Code"));
                ValidateTableRelation = false;
            }
        }
        procedure OnValidate
    ()
    
           "Desc 2": Record "Purchase Line"
        begin
            if "Desc 2".get(Rec."Shortcut Dimension 1 Code") then begin
                "Desc 2" := "Desc 2"
            end;
        end;
    
    
    }
    
    
    pageextension 50134 "Desc 2 " extends "Purch. Invoice Subform"
    {
        layout
        {
            addafter("Description 2")
            {
                field("Desc 2"; Rec."Desc 2")
                {
                    Caption = 'Desc 2';
                    ApplicationArea = all;
                }
            }
        }
    }

  • Suggested answer
    Nitin Verma Profile Picture
    21,812 Moderator on at

    Hi,

    Please replace your code with below.

    tableextension 50134 ModifyPurchLine extends "Purchase Line"

    {

       fields

       {

           field(50134; "Desc 2"; text[50])

           {

               DataClassification = ToBeClassified;

               Caption = 'Desc 2';

               TableRelation = "Dimension Value".Name where("Code" = field("Shortcut Dimension 1 Code"));

               ValidateTableRelation = true;

               trigger OnValidate()

               var

                   DimensionValue: Record "Dimension Value";

               begin

                   if DimensionValue.get(Rec."Shortcut Dimension 1 Code") then begin

                       "Desc 2" := DimensionValue.Name;

                   end;

           }

       }

    }

    pageextension 50134 ModifyPurchInvSubform extends "Purch. Invoice Subform"

    {

       layout

       {

           addafter("Description 2")

           {

               field("Desc 2"; Rec."Desc 2")

               {

                   Caption = 'Desc 2';

                   ApplicationArea = all;

               }

           }

       }

    }

    Let me know if it works for you.

  • Suggested answer
    YUN ZHU Profile Picture
    103,712 Super User 2026 Season 2 on at

    Hi, Thanks for the addition, I understand now, please try the following.

    tableextension 50134 "Desc 2" extends "Purchase Line"
    {
        fields
        {
            field(50134; "Desc 2"; text[50])
            {
                DataClassification = CustomerContent;
                Caption = 'Desc 2';
                TableRelation = "Dimension Value".Name where("Code" = field("Shortcut Dimension 1 Code"));
                ValidateTableRelation = false;
            }
    
            modify("Shortcut Dimension 1 Code")
            {
                trigger OnAfterValidate()
                var
                    GeneralLedgerSetup: Record "General Ledger Setup";
                    DimensionValue: Record "Dimension Value";
                begin
                    GeneralLedgerSetup.Get();
                    if DimensionValue.Get(GeneralLedgerSetup."Shortcut Dimension 1 Code", "Shortcut Dimension 1 Code") then
                        "Desc 2" := DimensionValue.Name;
                end;
            }
        }
    }
    
    
    pageextension 50134 "Desc 2 " extends "Purch. Invoice Subform"
    {
        layout
        {
            addafter("Description 2")
            {
                field("Desc 2"; Rec."Desc 2")
                {
                    Caption = 'Desc 2';
                    ApplicationArea = all;
                }
            }
        }
    }

    I have tested it.

    pastedimage1653636427830v1.png

    pastedimage1653636435047v2.png

    Thanks.

    ZHU

  • Suggested answer
    Nitin Verma Profile Picture
    21,812 Moderator on at

    Hi, Please change with the following after done some correction.

    tableextension 50134 "Desc 2" extends "Purchase Line"

    {

       fields

       {

           field(50134; "Desc 2"; text[50])

           {

               DataClassification = CustomerContent;

               Caption = 'Desc 2';

               TableRelation = "Dimension Value".Name where("Code" = field("Shortcut Dimension 1 Code"));

           }

           modify("Shortcut Dimension 1 Code")

           {

               trigger OnAfterValidate()

               var

                   GeneralLedgerSetup: Record "General Ledger Setup";

                   DimensionValue: Record "Dimension Value";

               begin

                   "Desc 2" := '';

                   GeneralLedgerSetup.Get();

                   DimensionValue.Reset();

                   DimensionValue.SetRange("Dimension Code", GeneralLedgerSetup."Shortcut Dimension 1 Code");

                   if DimensionValue.FindFirst() then

                       "Desc 2" := DimensionValue.Name;

               end;

           }

       }

    }

    pageextension 50134 "Desc 2 " extends "Purch. Invoice Subform"

    {

       layout

       {

           addafter("Description 2")

           {

               field("Desc 2"; Rec."Desc 2")

               {

                   Caption = 'Desc 2';

                   ApplicationArea = all;

               }

           }

       }

    }

  • rajivsewsarran Profile Picture
    44 on at

    Hi Nitin,

    Thanks for your assistance.

    However, the field still isn't auto populating for itself.

  • rajivsewsarran Profile Picture
    44 on at

    Hi Zhu, sorry i'm only now seeing your reply.

    I'll test this and let you know.

    Thanks!

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the August Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 740 Super User 2026 Season 2

#2
YUN ZHU Profile Picture

YUN ZHU 570 Super User 2026 Season 2

#3
Grigorios Mavrogeorgis Profile Picture

Grigorios Mavrogeorgis 291 Super User 2026 Season 2

Last 30 days Overall leaderboard

Featured topics

Microsoft Training Manuals

Product updates

Dynamics 365 release plans