Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

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

Inherit field from Customer Extension to Sales Order Extension

(0) ShareShare
ReportReport
Posted on by 93

Dear community members,

I have (hopefully) a question with a simple answer. I have tried searching for an answer on the web but without success, hence this post.

The question: How do I "inherit" an initial field value set on a Customer Card Extension (or Customer Table Extension) to the same field on a Sales Order Extension?

My scenario:

I have added two fields to the Customer table, the "Freight Payer" field and "Shipping Agent Customer No." field. Please see the code below.

On the Customer Card Extension page, I set the "standard" values for these two fields.

tableextension 50102 "Customer Ext." extends Customer
{
    fields
    {

        field(50100; "Freight Payer"; Option)
        {
            OptionMembers = "Sender", "Receiver";

        }

        field(50101; "Shipping Agent Customer No."; TEXT[20])
        {
            TableRelation = "Shipping Agent Cust. No. Table"."Shipping Agent Customer No." where("Customer No." = field("No."), "Shipping Agent Code" = field("Shipping Agent Code"));
            ValidateTableRelation = false;
        }
    }

}

On my Sales Order table extension, I have added the same fields.

What I want to do is that when I create a new sales order for the customer, the initial values set in the Customer table extension will be "transferred"/"inherited"
to the Sales Order. InitValue does not seem to work as when I type "Customer", no reference to the "Customer" table extension pops up.

See code below.

tableextension 50101 "Sales Order Table Ext." extends "Sales Header"
{
    fields
    {

        field(50100; "Freight Payer"; Option)
        {

            OptionMembers = "Sender", "Receiver";
            InitValue = //Get standard/initial value set in the Customer table extension.

        }

        field(50101; "Shipping Agent Customer No."; TEXT[20])
        {
            TableRelation = "Shipping Agent Cust. No. Table"."Shipping Agent Customer No." where("Customer No." = field("Sell-to Customer No."), "Shipping Agent Code" = field("Shipping Agent Code"));
            ValidateTableRelation = false;
            InitValue = //Get standard/initial value set in the Customer table extension.
        }
    }
}

  • Suggested answer
    Steven Renders Profile Picture
    5,500 Moderator on at
    RE: Inherit field from Customer Extension to Sales Order Extension

    Here you can find some more informtion:

    https://docs.microsoft.com/en-us/learn/modules/manipulate-data-via-code/

    https://docs.microsoft.com/en-us/learn/modules/events-triggers/

  • Marcus Halbauer Profile Picture
    93 on at
    RE: Inherit field from Customer Extension to Sales Order Extension

    Hello Stefano,

    That did the trick! Thank you very much again for your help!

  • Suggested answer
    Stefano Demiliani Profile Picture
    37,166 Most Valuable Professional on at
    RE: Inherit field from Customer Extension to Sales Order Extension

    Other possible way:

    [EventSubscriber(ObjectType::Table, Database::"Sales Header", 'OnAfterValidateEvent', 'Sell-to Customer No.', false, false)]

       local procedure AssignCustomerValues(var Rec: Record "Sales Header")

       var

           Customer: Record Customer;

       begin

           Customer.Get("Sell-to Customer No.")

           Rec."Freight Payer" := Customer."Freight Payer";

           Rec."Shipping Agent Customer No." := Customer."Shipping Agent Customer No.";

       end;

  • Suggested answer
    Stefano Demiliani Profile Picture
    37,166 Most Valuable Professional on at
    RE: Inherit field from Customer Extension to Sales Order Extension

    Here you have missed to retrieve the customer before retrieving the fields:

    CustomerRec.Get("Sell-to Customer No.");

  • Marcus Halbauer Profile Picture
    93 on at
    RE: Inherit field from Customer Extension to Sales Order Extension

    Hello again Stefano,

    Thank you for your help. How would you write the code for that?

    I have added the code below in the fields tag but it does not seem to achieve what I want.

    modify("Sell-to Customer No.")
    {
        trigger OnAfterValidate();
        var
            CustomerRec: Record Customer;
        begin
            "Freight Payer" := CustomerRec."Freight Payer";
            "Shipping Agent Customer No." := CustomerRec."Shipping Agent Customer No.";
        end;
    }

    Sorry for the stupid question, I am not used to AL-programming (yet).

  • Suggested answer
    Stefano Demiliani Profile Picture
    37,166 Most Valuable Professional on at
    RE: Inherit field from Customer Extension to Sales Order Extension

    You can handle the OnAfterValidate trigger of the Sell-to Customer No field (with an event subscriber in AL) and on this trigger transfer that data from Customer to the Sales Header

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

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

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

#1
YUN ZHU Profile Picture

YUN ZHU 592 Super User 2025 Season 1

#2
Mansi Soni Profile Picture

Mansi Soni 453

#3
Sagar Dangar, MCP Profile Picture

Sagar Dangar, MCP 391

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans