2

I have made a query in AOT. My goal is to print information using Group by "CustGroup" and Order by "count(RecId)" desc of CustTable table. The group by works properly, but the order by does not. I can not understand why...

This is what my query looks like:

enter image description here

This is code I use:

Static void Query(Args _args)
{
   QueryRun  qr;
   CustTable myCustTable;
;
   qr = new QueryRun(queryStr(MyQuery));
while(qr.next())
{
  myCustTable = qr.get(tableNum(CustTable));
  info(strFmt("Group %1  Num %2", myCustTable.Custgroup, myCustTable.RecId));
}
}

The result is:

enter image description here

Jan B. Kjeldsen
  • 17,817
  • 5
  • 32
  • 50
AYETY
  • 698
  • 4
  • 23
  • 38

1 Answers1

2

AX does not sort by Count(RecId) but by the grouping.

You can solve your problem by dragging your query to a new view, then doing the sort on the count field of the view. You can also define the view without a query.

Jan B. Kjeldsen
  • 17,817
  • 5
  • 32
  • 50
  • Hello Jan, thanks for help. I have one question about RecIds in View. When I created View like I wanted and I noticed that all RecIds in View are the same '1010'. Can you tell me why they are not unique like in tables? – AYETY Mar 25 '14 at 14:07
  • 1
    If you did the `count(RecId)` (or other aggregations) it will have that value. In views without aggregation it will have the `RecId` value from the first table. Otherwise it will have an arbitrary nonzero value like 1010. Uniqueness is not an issue, as you cannot update the view or sanely select the aggregate by `RecId`. – Jan B. Kjeldsen Mar 25 '14 at 14:32