Skip to main content

Notifications

Small and medium business | Business Central, N...
Suggested answer

Update field on Sales Line After Modify

(1) ShareShare
ReportReport
Posted on by 14
I have a table extension on the Sales Order table with a field named "Net_Weight". When this field is modified, I need to update the Quantity field on the records of the Sales LIne.
 
I'm was trying yo use a trigger but cannot get it to work correctly.
 
I would appreciate any guidance provided.
  • Suggested answer
    Khushbu Rajvi. Profile Picture
    Khushbu Rajvi. 7,589 Super User 2025 Season 1 on at
    Update field on Sales Line After Modify
    just adding more info:  Basically in this type of scenario You need to filter Sales Line (NetSL) using SetRange("Document Type", Rec."Document Type") and SetRange("Document No.", Rec."No.") to get the correct lines related to the Sales Header (NetHL). Then, use FindSet() to loop through and update the Quantity.
  • MJ-27012000-0 Profile Picture
    MJ-27012000-0 14 on at
    Update field on Sales Line After Modify
    Success...Thank you so much for everyone that assisted. You people are the best!
  • gdrenteria Profile Picture
    gdrenteria 13,553 Most Valuable Professional on at
    Update field on Sales Line After Modify

    Hi, good day
    I hope this can help you, and give you some hints.

    Record.Get([Any,...]) Method - Business Central | Microsoft Learn

     

    Gets a record based on values stored in primary key fields.

     

    Best Regards
    Gerardo

  • Suggested answer
    YUN ZHU Profile Picture
    YUN ZHU 76,716 Super User 2025 Season 1 on at
    Update field on Sales Line After Modify
    The problem is in this line, you didn't get the data.
    The primary key of Sales Line is not Net Weight.
    You can continue to use Get, or you can use Setrange/SetFilter -> FindFirst.
     
    Here is an example I gave in response to another question: At least the filtering part is similar
    Hope  this can give you some hints.
    Thanks
    ZHU
  • MJ-27012000-0 Profile Picture
    MJ-27012000-0 14 on at
    Update field on Sales Line After Modify
    I also tried this without success...
     
            Modify("Net Weight")
            {
                Trigger OnAfterValidate()
                var
                    NetSL: record "Sales Line";
                    NetHL: record "Sales Header";
                begin
                    If NetHL.Get(rec."Net Weight") Then begin
                        NetSL.Quantity := (NetHL."Net Weight");
                        //NetSL.Modify(true);
                        NetSL.ModifyAll(NetSL.Quantity, NetHL."Net Weight");
                        CurrPage.Update();
                    end;
                end;
     
            }
  • MJ-27012000-0 Profile Picture
    MJ-27012000-0 14 on at
    Update field on Sales Line After Modify
    Thanks ZHU, but that did not work either.
     
    Do you have any other ideas?
     
    Thanks!
     
     
     
  • Suggested answer
    YUN ZHU Profile Picture
    YUN ZHU 76,716 Super User 2025 Season 1 on at
    Update field on Sales Line After Modify
  • MJ-27012000-0 Profile Picture
    MJ-27012000-0 14 on at
    Update field on Sales Line After Modify
    ZHU
     
    This is what i have...
     
    pageextension 50121 SalesOrderExtension extends "Sales Order"
    {
        layout
        {
     
            addafter(General)
            {
                Group("BOL Information")
                {
                    field("Equipment No."; rec."Equipment No.")
                    {
                        ApplicationArea = All;
                        Caption = 'Equipment No.';
                        ToolTip = 'Enter Equipment No.';
                    }
                    field("Method"; rec."Method")
                    {
                        ApplicationArea = All;
                        Caption = 'Method';
                        ToolTip = 'Select Method';
                    }
                    field("Seal Numbers"; rec."Seal")
                    {
                        ApplicationArea = All;
                        Caption = 'Seal Numbers';
                        ToolTip = 'Enter Seal Numbers';
                    }
                    field("Net Weight"; rec."Net Weight")
                    {
                        ApplicationArea = All;
                        Caption = 'Net Weight';
                        ToolTip = 'Enter Net Weight';
                    }
                    field("Tare Weight"; rec."Tare Weight")
                    {
                        ApplicationArea = All;
                        Caption = 'Tare Weight';
                        ToolTip = 'Enter Tare Weight';
                    }
                    field("Gross Weight"; rec."Gross Weight")
                    {
                        ApplicationArea = All;
                        Caption = 'Gross Weight';
                        ToolTip = 'Enter Gross Weight';
                    }
     
                }
            }
            Modify("Sell-to Customer No.")
            {
                Trigger OnAfterValidate()
                var
                    NetSL: record "Sales Line";
                    NetHL: record "Sales Header";
                begin
     
     
                    If NetHL.Get(rec."Net Weight") Then begin
                        NetSL.Quantity := (rec."Net Weight");
                        CurrPage.Update();
                    end;
     
                end;
     
     
            }
     
     
        }
     
    }
  • YUN ZHU Profile Picture
    YUN ZHU 76,716 Super User 2025 Season 1 on at
    Update field on Sales Line After Modify
    What trigger did you try? It would be helpful if you could share the code.
    Usually, this can be done using OnValidate (Field) trigger.
     
    Thanks.
    ZHU
  • Suggested answer
    tanya07 Profile Picture
    tanya07 1,596 on at
    Update field on Sales Line After Modify
    Hello,
     
     
    You can use the above trigger.
     
    Hope this helps.
     
    Thanks,
    TK

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…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Vahid Ghafarpour – Community Spotlight

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

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,965 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,779 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans