static void countRecords(Args _args) { Query q = new Query(); QueryBuildDataSource qbdsInventTable, qbdsInventDimCombination; QueryRun qr; Integer counter; Integer loops; Common common; qbdsInventTable = q.addDataSource(tableNum(InventTable)); qbdsInventTable.addSelectionField(fieldNum(InventTable, RecId), SelectionField::Count); qr = new QueryRun(q); // Simple way to get record count from Query/QueryRun class counter = SysQuery::countTotal(qr); //loops = SysQuery::countLoops(qr); // Via while counter = 0; loops = 0; while (qr.next()) { common = qr.get(q.dataSourceNo(1).table()); counter += common.RecId; } /* Second variant might be a lot more efficient and accurate if you have several datasources joined as standard countTotal also tries to count loops Adding joined datasource for you to checkout the difference */ qbdsInventDimCombination = qbdsInventTable.addDataSource(tableNum(InventDimCombination)); qbdsInventDimCombination.relations(true); qr = new QueryRun(q); // Way to get record count using SysQuery counter = SysQuery::countTotal(qr); //loops = SysQuery::countLoops(qr); // Via while loops = 0; counter = 0; while (qr.next()) { common = qr.get(q.dataSourceNo(1).table()); counter += common.RecId; } }
留言评论
暂无留言