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...
Suggested Answer

Update Location Code on Sales Header from Sales Line

(0) ShareShare
ReportReport
Posted on by 130

Hi All,

I need to populate Sales Header Location with the Location code on the first Sales Line here I have done this 

procedure SetLocationCodeBySalesLine(Var Rec: Record "Sales Line"; CurrFieldNo: Integer; var xRec: Record "Sales Line")
    Var
        SalesHeader: Record "Sales Header";
    begin
        SalesHeader.Get(Rec."Document Type", Rec."Document No.");
        if Rec.FindFirst() then
            // if Rec."Line No." = 10000 then
             if (Rec."Location Code" <> '') AND (SalesHeader."Location Code" <> Rec."Location Code") then begin
                SalesHeader.Validate("Location Code", Rec."Location Code");
                // SalesHeader."Location Code" := Rec."Location Code";
                SalesHeader.Modify();
            end;


    end;

    [EventSubscriber(ObjectType::Table, Database::"Sales Line", 'OnAfterValidateEvent', 'Location Code', false, false)]
    local procedure OnAfterValidateEvent(var Rec: Record "Sales Line"; CurrFieldNo: Integer; var xRec: Record "Sales Line")
    begin
        SetLocationCodeBySalesLine(Rec, CurrFieldNo, xRec);
    end;
but "in the sales line when I update the location code in sales line it is not taking the location code which I gave can anyone please suggest me this."
I have the same question (0)
  • Suggested answer
    Nitin Verma Profile Picture
    21,708 Moderator on at

    Hi,

    Did you try below?

    [EventSubscriber(ObjectType::Table, Database::"Sales Line", 'OnAfterValidateEvent', 'No.', false, false)]

       local procedure OnAfterValidateEvent(var Rec: Record "Sales Line"; CurrFieldNo: Integer; var xRec: Record "Sales Line")

       var

           SalesHdr: Record "Sales Header";

       begin

           if SalesHdr.get(rec."Document Type", rec."Document No.") then begin

               rec.Validate("Location Code", SalesHdr."Location Code");

               rec.Modify();

           end;

       end;

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,238

#2
YUN ZHU Profile Picture

YUN ZHU 773 Super User 2025 Season 2

#3
Sumit Singh Profile Picture

Sumit Singh 630

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans