1

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?

1

1 Answer 1

2

You cannot (in X++) sort on an aggregated field.

What you can do is make a view, then sort on its output explained in this answer and here.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.