How to Count Row's from Table in Ax 2012

 
Description:-

In this article we will Create Dynamics Query for Count Table rows in ax. Here I have created dynamics Query to count table row. One more way you can count your table rows by scrolling in table but if we want in code behind some other action to perform on table or we pass totals rows to do some action after on the table then we have to use code for count table row.

Here I have created demo example so you can check by code through count table rows. In this query I have used SysQuery::Counttotals (Query) to count Query by passed table in that Query.  Follow these steps to count table rows and create table in ax.

Step 1: Create Table Name it “A_Student”.

 1) Expand AOT Node.
2) Open Data Dictionary Node.
3) Select Tables and right Click Select New Table.
4) Name it “A_Student”.
5) Now open table in Insert Some Data in A_Student table. 


After Insert Some Data in A_Student table so we can count how many Rows are in table.


Now Create Job Using Query Run How to Count Row’s from table or else you can returns rows if you are using while loop in other method for checking how many rows are in table.

Create Job from AOT

        1. In the AOT, click Job.
        2. Right-click the Job node, and then select New Job.

Static void Query_cntRecords(Args _args)
{
    Query                query = newQuery();
    QueryRun             queryRun;
    QueryBuildDataSource qbd;
    ;
qbd = query.addDataSource(tablenum(A_Student));
queryRun = new QueryRun(query);
info(strfmt("Total Records in Query %1",SysQuery::countTotal(queryRun)));
//return SysQuery::countTotal(queryRun);
}

Now run your job you will get counted record from table in Info log.



Related Posts

Previous
Next Post »

Thanks for comments.....