How to count records in a Query

Example Code Query   q; QueryRun qr; q = new Query; q.addDataSource(tableNum(CustTable), tableStr(CustTable)); qr = new QueryRun(q); info(int2str(SysQuery::countTotal(qr)));

As seen you can use SysQuery object.

Runtime / Performance considerations
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.

public void executeQuery {   super; info(int2str(SysQuery::countLoops(InventTable_ds.queryRun))); }