GroupBy

How to apply Groupby through code ?Urgently need a solution

Following code will help you in applying the Group By function-

Group By & Field sum query-

QueryBuildFieldList qbfl = qbds.fields();

qbds = q.addDataSource(tablenum(SalesLine));

//QBFL
qbfl.addField(fieldNum(SalesLine,SalesQty),SelectionField::Sum);

qbds.addSortField(fieldnum(SalesLine,ItemId));
qbds.orderMode(OrderMode::GroupBy);

qr = new QueryRun(q);
while(qr.next())
{
salesLine = qr.get(tablenum(SalesLine));
info(strfmt(‘Item Id =%1, Qty = %2’,salesLine.ItemId,salesLine.SalesQty));
}

Note:In the same way Group by can be used in the while select statement as well.

thanx for reply…:slight_smile: