Не знаю, поможет ли, но попробуй вот этот метод использовать (его добавить надо в класс SysQuery)
X++:
public client server static Integer dev_countTotal(Query _query)
{
int k;
Query countQuery = _query.newObject(_query.pack(FALSE));
QueryRun countQueryRun;
QueryBuildDataSource dataSource = countQuery.dataSourceNo(1);
QueryBuildFieldList theFieldList = dataSource.fields();
Common record;
int ret = 0;
// Add contribution from dynalinks...
countQuery = SysQuery::copyDynalinks(countQuery, _query);
theFieldList.addField(fieldnum(Common, RecId), SelectionField::COUNT);
for (k = 2; k <= countQuery.dataSourceCount();k++)
{
dataSource = countQuery.dataSourceNo(k);
theFieldList = dataSource.fields();
theFieldList.dynamic(false);
theFieldList.clearFieldList();
theFieldList.addField(fieldNum(Common,TableId));
}
countQueryRun = new QueryRun(countQuery);
while (countQueryRun.next()) {
record = countQueryRun.getNo(1);
ret += record.RecId;
}
return ret;
}