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

Notifications

Announcements

Community site session details

Community site session details

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

Add the total of a column on a list page

(0) ShareShare
ReportReport
Posted on by 92

On the "Purchase Invoices" page, I want to create a "Totals" section, where the "Amount" and "Amount including VAT" fields of all records are added. To achieve this, I am using the following code:

trigger OnAfterGetCurrRecord()
    var
        PurchaseHeader: Record "Purchase Header";
    begin
        PurchaseHeader.CopyFilters(Rec);
        PurchaseHeader.CalcSums(Amount, "Amount Including VAT");
        TotalAmount := PurchaseHeader.Amount;
        TotalAmountIncludingVAT := PurchaseHeader."Amount Including VAT";
    end;
But it doesn't work, variables always appear in "0". Use this same code in a page created by myself and there if it worked, do I have to change something as it is a default page or am I making a mistake? Some alternative?
I have the same question (0)
  • Suggested answer
    Nitin Verma Profile Picture
    21,748 Moderator on at

    Hi,

    I think you should think about your requirement once again, if you are thinking to sum of all the records amount and show, so I would suggest please use the Fact box and in the fact box do the sum of all records and show the total amount of all the records while opening.

    Factbox

    trigger OnOpenPage()

       var

           PurchaseHeader: Record "Purchase Header";

       begin

           PurchaseHeader.reset;

           PurchaseHeader.setrange("Document Type",PurchaseHeader."Document Type"::Invoice);

           PurchaseHeader.setloadfields(Amount, "Amount Including VAT");

           if PurchaseHeader.findset then

           begin

                 PurchaseHeader.CalcSums(Amount, "Amount Including VAT");

                 TotalAmount := PurchaseHeader.Amount;

                 TotalAmountIncludingVAT := PurchaseHeader."Amount Including VAT";

           end;

       end;

  • Suggested answer
    DAnny3211 Profile Picture
    11,401 on at

    Hi

    you can also create a function within the page that performs the calculation you want to obtain and create a section where you can insert your function that will output your two fields

    DAniele

  • Suggested answer
    YUN ZHU Profile Picture
    97,216 Super User 2025 Season 2 on at

    Hi, just adding some info.

    If you need to sum all the invoices on the page, please refer to Natin's code.

    If you just need the total of the current invoice, these are the standard fields, you just need to display them on the page.

    pastedimage1670391835340v1.png

    Hope this helps.
    Thanks.
    ZHU

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…

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 1,957

#2
Dhiren Nagar Profile Picture

Dhiren Nagar 1,245

#3
YUN ZHU Profile Picture

YUN ZHU 1,045 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans