Aug 27, 2012

How to count the number of records in a report in ax 2009.

Sometimes we need to calculate the percentages in the report basing on the number of records which are displaying in the report. To achieve that first we need to calculate the number of records in report.
By using  SysQuery::countLoops() method we can calculate the number of records.

Actually i used many tables in this particular report but the main table in SalesTable. i am building the dynamics query and joining all rest of the tables into this table. so my main table in this report is SalesTable and my query name is queryRun_1. I used this query in the fetch method.
the code should be as shown below.

  while(queryRun_1.next())
         {
            SalesTable = queryRun_1.get(tablenum(salesTable));


             this.send(SalesTable);


           NOR =  SysQuery::countLoops(queryRun_1);

         }

countLoops is the method which is used to count the number of loops while query is executing from the class SysQuery.
And NOR is just a variable to count the number of records which is declared in class declaration so that we can used it anywhere in our report.

No comments: