I want to count how many records are there in CustTable (group by CustGroup) and sort the number of records in each custgroup descending using query code.
here is my code:
q = new Query();
queryBuildDataSource = q.addDataSource(tableNum(custTable));
queryBuildDataSource.addGroupByField(fieldNum(custTable, CustGroup));
//queryBuildDataSource.addSortField(fieldNum(custTable, count(RecId), SortOrder::Descending));
qr = new QueryRun(q);
while(qr.next())
{
custTable = qr.get(tableNum(custTable));
info(strFmt("%1 --- %2", custTable.CustGroup, custTable.RecId));
}
I know that 'count' does not work here... how can I solve it?