Calculating Customer Aging Balances in X++

By Laura Lake | May 23, 2017

I was recently asked to add an Account Summary to the footer of a report in AX 2012, to look something like this:


In my research, I came across a helpful class that allowed me to meet this requirement of calculating customer aging balances in X++ with a minimum of coding effort; the CustVendAgingStatistics class. The calcStatistic method queries StatRepInterval and StatRepIntvervalLine to get the buckets and settings for the calculation, then it writes out the values to tmpAccountSum, which is an InMemory temporary table. Depending on what aging buckets you need, you can use a debugger to figure out which tmpAccountSum records you will want.

For my purpose, I created a new method to calculate the customer’s aging balances using a 30D format (#agingFormat macro). I needed open balances (Balance03) and I opted to store both balance and description in a Map. The integer key was helpful so that I could retrieve the values later and add them to the SalesInvoiceHeaderFooterTmp record in SalesInvoiceDP.insertSalesInvoiceHeaderFooterTmp method. You could easily use a container here, depending on how you are using the aging information.

private void SSI_calcAging(CustInvoiceAccount _invoiceAccount)
    CustVendTable               custVendTable;
    CustVendAgingStatistics     custVendAgingStats;
    TmpAccountSum               tmpAccountSumLocal;
    int                         i;
    custVendTable  = CustTable::find(_invoiceAccount);

    custVendAgingStats =       CustVendAgingStatistics::construct(custVendTable,#agingFormat,
    i = 0;
    cachedaccountSummary = new Map(Types::Integer,Types::Real);
    cachedaccountSummaryTxt = new Map(Types::Integer,Types::String);
    while select tmpAccountSumLocal


Obviously, this could be used for Vendor Aging as well. I verified that the values match exactly with the Customer Aging report when it is run with the same parameters.

Start the Conversation

It’s our mission to help clients win. We’d love to talk to you about the right business solutions to help you achieve your goals.

Subscribe To Our Blog

Sign up to get periodic updates on the latest posts.

Thank you for subscribing!