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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Dynamics 365 Community / Blogs / That NAV Guy / D365 Business Central : Add...

D365 Business Central : Adding Total to Sales Order Page

Teddy Herryanto (That NAV Guy) Profile Picture Teddy Herryanto (Th... 14,306 Super User 2026 Season 1

If you look at the Sales Order page, you can see that there are total fields under the Lines section. I recently had a request to add another total field to it, such as Quantity. To do this, we can easily subscribe to the Document Totals codeunit.

The Document Totals codeunit is used to calculate total on sales and purchase documents.

Let’s try to subscribe to the events.

There are two events that you need to subscribe: OnAfterCalculateSalesSubPageTotals and OnAfterSalesDeltaUpdateTotals. We are going to use the existing Quantity field to collect the Total Quantity.

codeunit 60001 "Subs Document Totals_TNG"
{
    SingleInstance = true;

    [EventSubscriber(ObjectType::Codeunit, Codeunit::"Document Totals", 'OnAfterSalesDeltaUpdateTotals', '', false, false)]
    local procedure DocumentTotals_OnAfterSalesDeltaUpdateTotals(var TotalSalesLine: Record "Sales Line"; var SalesLine: Record "Sales Line"; var xSalesLine: Record "Sales Line")
    begin
        TotalSalesLine.Quantity += SalesLine."Quantity" - xSalesLine."Quantity";
    end;

    [EventSubscriber(ObjectType::Codeunit, Codeunit::"Document Totals", 'OnAfterCalculateSalesSubPageTotals', '', false, false)]
    local procedure DocumentTotals_OnAfterCalculateSalesSubPageTotals(var TotalSalesLine2: Record "Sales Line")
    begin
        TotalSalesLine2.CalcSums(Quantity);
    end;
}

After subscribing to the codeunit, we just need to add page extension to show the field. I am going to put it before the Total Amount Excluding VAT.

pageextension 60001 "Sales Order Subform_TNG" extends "Sales Order Subform"
{
    layout
    {
        addbefore("Total Amount Excl. VAT")
        {
            field("Total Quantity_TNG"; TotalSalesLine.Quantity)
            {
                ApplicationArea = Basic, Suite;
                DecimalPlaces = 0 : 5;
                Caption = 'Total Quantity';
                Editable = false;
                ToolTip = 'Specifies the sum of the quantity on all lines in the document.';
            }
        }
    }
}

Let’s try publishing it.

That’s it. Hope that helps.

Sample source available on Git Hub.

The post D365 Business Central : Adding Total to Sales Order Page appeared first on That NAV Guy.


This was originally posted here.

Comments

*This post is locked for comments