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 :
Small and medium business | Business Central, N...
Answered

What is the best way to include the total of any column in a Word Layout Report Extension?

(1) ShareShare
ReportReport
Posted on by 117
Hi Everyone,
 
This is a Word layout Report Extension, and I am trying to sum of Sales Amount column that I have added to a report where I want to sum the sales amount. Please let me know what I need to do. I have searched a lot but did not find documentation about Word layouts related to totaling.
 
reportextension 51011 DetailSalesPersonReportExt extends 7141758
{
 
    dataset
    {
        add(DetailedCommissEntry)
        {
            column(Payment_Date; Format(paymentDate)) { }
            column(Sales_Amount; "Sales Amount")
            {
 
            }
 
        }
        add(Totals)
        {
            column(TotalSalesAmt; TotalSalesAmt)
            {
 
            }
 
        }
 
        modify(Totals)
        {
            trigger OnAfterAfterGetRecord()
            var
            // DetailCommissionEntry: Record "IDPCOS Detailed Commiss. Entry";
            begin
                TotalSalesAmt += DetailedCommissEntry."Sales Amount";
 
            end;
 
        }
 
    }
 
    requestpage
    {
 
    }



 
    rendering
    {
        layout(NewLayout)
        {
            Type = Word;
            LayoutFile = 'Layouts/Detail SalesPerson Default - Letter.docx';
            Caption = 'Custom layout By UC (Letter Formart)';
            Summary = 'Includes the information most commonly requested by users.';
 
        }
    }
    labels
    {
        PaymentDateLbl = 'Payment Date';
        ProfitLbl = 'Profit Amount';
        SalesAmountLbl = 'Sales Amount';
 
    }
 
    trigger OnPreReport()
    var
        LastDocumentNo: Code[20];
        RecRef: RecordRef;
        DetailCommissionEntry: Record "IDPCOS Detailed Commiss. Entry";
    begin
        /*  Clear(TotalSalesAmt);
         TotalSalesAmt := 0; */
        /*
            DetailCommissionEntry.Reset();
           // DetailCommissionEntry.CopyFilters(Salesperson);
            if DetailCommissionEntry.FindSet() then
                repeat
                    TotalSalesAmt += DetailCommissionEntry."Sales Amount";
                until DetailCommissionEntry.Next() = 0; */
 
    end;
 
    trigger OnPostReport()
    var
        myInt: Integer;
        LastDocumentNo: Code[20];
    begin


 
    end;
 
    var
        PaymentDateLbl: Label 'PaymentDate';
        ProfitLbl: Label 'ProfitAmt';
        SalesAmountLbl: Label 'SalesAmt';
 
        TotalSalesAmt: Decimal;
 
}
 
 
 Report Output
 
 
 
I have the same question (1)
  • Verified answer
    YUN ZHU Profile Picture
    99,322 Super User 2026 Season 1 on at
    Hi, You can refer to the standard code, because you need to loop and sum, you can try to add your code to the OnAfterPostDataItem of the data.
    For example, Note the use of the keyword modify, not add.
     
    Hope this helps.
    Thanks.
    ZHU
  • Suggested answer
    Faisal Qureshi Profile Picture
    117 on at

    Thanks, YUH ZHU Sir for your valuable answer, the OnAfterPostDataItem trigger only adds only the first record, so I added the same code to the OnAfterAfterGetRecord trigger and Sales Amount Total shows as expected. You're right, I have modified the DetailedCommissEntry data item.

     
           modify(DetailedCommissEntry)
            {
                trigger OnAfterAfterGetRecord()
                var
                    myInt: Integer;
                begin
                    TotalSalesAmt += DetailedCommissEntry."Sales Amount";
                end;
            }
     
        }
     
    Report output
     
     

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 1,922 Super User 2026 Season 1

#2
YUN ZHU Profile Picture

YUN ZHU 1,078 Super User 2026 Season 1

#3
Khushbu Rajvi. Profile Picture

Khushbu Rajvi. 628 Super User 2026 Season 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans