AX – D365FO – Count records in Query #d365fo

If your query has just one datasource you can use SysQuery::countTotal

static void CountProjTableRecords(Args _args)
{      
    Query                           query = new Query();    
    QueryRun                     queryRun;    
    QueryBuildDataSource qbd;    
    qbd = query.addDataSource(tablenum(ProjTable));   
    queryRun = new QueryRun(query);   
    info(strfmt("Total Records in Query %1", SysQuery::countTotal(queryRun))); // total records 1130
}

If we need to count number of records of a query with more than one datasource, you must use SysQuery::CountLoops(QueryRun).

static void CountProjTableRecords(Args _args)
{      
    Query                           query = new Query();    
    QueryRun                     queryRun;    
    QueryBuildDataSource qbds, qbds1;    
    qbds = query.addDataSource(tablenum(ProjTable));    
    qbds1 = query.addDataSource(tablenum(ProjTable)).addDataSource(tablenum(ProjForecastTable));    
    queryRun = new QueryRun(query);   
    info(strfmt("Total Records in Query %1", SysQuery::countLoops(queryRun))); 
}
 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s