web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

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

Get sum of all line items on Insert, Delete, Modify

(0) ShareShare
ReportReport
Posted on by

Hi, 

I wanted to get sum of qunatity from Sales Lines on sales Order Page. Thus, I created TableExtension.

tableextension 50103 SalesLinesTable extends "Sales Line"
{
    fields
    {
        // Add changes to table fields here
        field(50101; "Sum of Quantity"; Decimal)
        {

            AccessByPermission = TableData Location = R;
            BlankZero = true;
            CalcFormula = Sum ("Sales Line".Quantity
            WHERE("Document No." = FIELD("Document No.")));
            DecimalPlaces = 0 : 5;
            Editable = false;
            FieldClass = FlowField;
            trigger OnValidate()
            begin
                ILE.Reset();
                ILE.Setcurrentkey("No.", "Location Code");

                ILE.Setrange("No.", "No.");

                ILE.Setrange("Location Code", "Location Code");

                IF ILE.FINDFIRST THEN BEGIN

                    ILE.Calcsums(Quantity);

                    decQty := ILE.Quantity;

                END;
            end;
        }

    }
    trigger OnInsert()
    begin
        ILE.Reset();
        ILE.Setcurrentkey("No.", "Location Code");

        ILE.Setrange("No.", "No.");

        ILE.Setrange("Location Code", "Location Code");

        IF ILE.FINDFIRST THEN BEGIN

            ILE.Calcsums(Quantity);

            decQty := ILE.Quantity;

        END;
    end;

    trigger OnDelete()
    begin
        ILE.Reset();
        ILE.Setcurrentkey("No.", "Location Code");

        ILE.Setrange("No.", "No.");

        ILE.Setrange("Location Code", "Location Code");

        IF ILE.FINDFIRST THEN BEGIN

            ILE.Calcsums(Quantity);

            decQty := ILE.Quantity;

        END;
    end;

    trigger OnModify()
    begin
        ILE.Reset();
        ILE.Setcurrentkey("No.", "Location Code");

        ILE.Setrange("No.", "No.");

        ILE.Setrange("Location Code", "Location Code");

        IF ILE.FINDFIRST THEN BEGIN

            ILE.Calcsums(Quantity);

            decQty := ILE.Quantity;

        END;
    end;

    var
        ILE: Record "Sales Line";
        decqty: Integer;


}
However, When I open page it's working fine. But, when I am inserting record deleting then it's  not changing value at the same time in a field. Please help me solve this.
Thank You
I have the same question (0)
  • Suggested answer
    Andy Sather Profile Picture
    on at
    RE: Get sum of all line items on Insert, Delete, Modify

    Hello  - We currently do not have dedicated Dev support via the Dynamics 365 Business Central forums, but I wanted to provide you some additional resources to assist.  If you need assistance with debugging or coding I would recommend discussing this on one of our communities.

    www.yammer.com/dynamicsnavdev

    dynamicsuser.net/.../developers

    I will open this up to the community in case they have something to add.

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

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

#1
Rishabh Kanaskar Profile Picture

Rishabh Kanaskar 3,401

#2
Sumit Singh Profile Picture

Sumit Singh 2,692

#3
YUN ZHU Profile Picture

YUN ZHU 1,935 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans