Monday, November 2, 2015

How to fetch number of records in datasource in Dynamics AX

I am going to share through post that sometimes we need to retrieve the number of records in a particular datasource. Let's say we have two datasources in a form named Student and StudentCourseEnrollment.

I simply need to fetch the number of records in Student Datasource in the init event of the the form. I would require following peace of code for that.


public void init()
{
    QueryRun queryRun;

    super();

    queryRun = new QueryRun(Student_ds.query());


    info(strfmt("Total Records in Student Datasource %1",SysQuery::countTotal(queryRun)));

}

Further you can refer this post to retrieve the rows from the temporary data source as well.