Axaptapedia is now maintained by AgileCadence For more information please click here.
How to count records in a Query
Example Code <xpp> Query q; QueryRun qr;
q = new Query(); q.addDataSource(tableNum(CustTable), tableStr(CustTable)); qr = new QueryRun(q); info(int2str(SysQuery::countTotal(qr))); </xpp>
As seen you can use SysQuery object.
Runtime / Performance considerations[edit]
The call you are doing here works well if and only if you have exactly one datasource in the query. In the case you are starting to join up stuff here, things get complicated, as the implementation behind this call (specifically SysQuery::countPrim()) does actually loop over the entire resultset. It has to be taken with care therefore.
well, if you have more than one datasource in the query, you can try "SysQuery::countLoops", in order to just count the top level datasource.
Example:
you can use this method to count all the ItemIds in the current datasource(InventTable) of "InventTable" Form.
<xpp> public void executeQuery() {
super(); info(int2str(SysQuery::countLoops(InventTable_ds.queryRun())));
} </xpp>