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

Notifications

Announcements

No record found.

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
    95,763 Super User 2025 Season 2 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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,116

#2
Khushbu Rajvi. Profile Picture

Khushbu Rajvi. 764 Super User 2025 Season 2

#3
YUN ZHU Profile Picture

YUN ZHU 635 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans