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."
  • Suggested answer
    Nitin Verma Profile Picture
    Nitin Verma 21,273 Moderator on at
    RE: Update Location Code on Sales Header from Sales Line

    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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,489 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,305 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans