Dynamics 365 Business Central: How to add new fields to Total Area on the Document Subform page (View Total Quantity, Number of Lines on the Sales Order)

Dynamics 365 Business Central

Hi, Readers.
Today I would like to talk about a basic requirement, how to add new fields to Total Area on the Document Subform page.

Let’s take a look at Sales Order. The totals fields under the lines are automatically updated as you create or modify lines to display the amounts that will be posted to the ledgers. However, the standard Business Central only provides fields related to the amount. If we want to view such as total quantity and number of lines, can we customize it?

Yes, of course. First of all, we need to note that this Total Area is not on the Sales Order page, but on the Sales Order Subform (46, ListPart) page.

Let’s see a specific example. Add Total Quantity and Number of Lines on the Sales Order, and need to be updated automatically just like other totals fields.

The following is just a situation, for reference only.

1. Add new fields to the page, only the variables is needed here.

2. Add logic for automatic calculation.

3. Execute the automatic calculation logic in the required trigger.

Publish to the environment.

Test Video:

Source Code:

pageextension 50114 ZYSalesOrderSubformExt extends "Sales Order Subform"
{
    layout
    {
        addlast(Control28)
        {
            field(TotalQuantity; TotalQuantity)
            {
                Caption = 'Total Quantity';
                ApplicationArea = All;
                Editable = false;
            }
            field(NumberOfLines; NumberOfLines)
            {
                Caption = 'Number Of Lines';
                ApplicationArea = All;
                Editable = false;
            }
        }

        modify(Quantity)
        {
            trigger OnAfterValidate()
            begin
                UpdateTotalQtyAndNumberOfLines();
            end;
        }
    }

    trigger OnAfterGetCurrRecord()
    begin
        UpdateTotalQtyAndNumberOfLines();
    end;

    trigger OnInsertRecord(BelowxRec: Boolean): Boolean
    begin
        UpdateTotalQtyAndNumberOfLines();
    end;

    trigger OnDeleteRecord(): Boolean
    begin
        UpdateTotalQtyAndNumberOfLines();
    end;

    var
        TotalQuantity: Decimal;
        NumberOfLines: Integer;

    procedure UpdateTotalQtyAndNumberOfLines()
    var
        SalesLine: Record "Sales Line";
    begin
        TotalQuantity := 0;
        NumberOfLines := 0;
        SalesLine.Reset();
        SalesLine.CopyFilters(Rec);
        SalesLine.CalcSums(Quantity);
        TotalQuantity := SalesLine.Quantity;
        NumberOfLines := SalesLine.Count;
    end;
}

PS: We also discussed how to calculate and display the total amount or quantity of selected lines on the list page before.

END

Hope this will help.

Thanks for reading.

ZHU

コメント

Copied title and URL