web
You’re offline. This is a read only version of the page.
close
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 100

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.
        }
    }
}

I have the same question (0)
  • Suggested answer
    Stefano Demiliani Profile Picture
    37,166 Most Valuable Professional on at

    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

  • Marcus Halbauer Profile Picture
    100 on at

    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

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

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

  • Suggested answer
    Stefano Demiliani Profile Picture
    37,166 Most Valuable Professional on at

    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;

  • Marcus Halbauer Profile Picture
    100 on at

    Hello Stefano,

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

  • Suggested answer
    Steven Renders Profile Picture
    5,672 Moderator on at

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,135

#2
YUN ZHU Profile Picture

YUN ZHU 733 Super User 2025 Season 2

#3
Sumit Singh Profile Picture

Sumit Singh 612

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans