Skip to main content

Notifications

Announcements

No record found.

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?
  • Suggested answer
    YUN ZHU Profile Picture
    YUN ZHU 76,009 Super User 2024 Season 2 on at
    RE: Add the total of a column on a list page

    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

  • Suggested answer
    DAnny3211 Profile Picture
    DAnny3211 9,274 Super User 2024 Season 1 on at
    RE: Add the total of a column on a list page

    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
    Nitin Verma Profile Picture
    Nitin Verma 21,081 Super User 2024 Season 1 on at
    RE: Add the total of a column on a list page

    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;

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

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey Pt 2

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,791 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,488 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans