SalesLine _salesLine;
InventTable _inventTable ;
int a =0 ;
Query query = new Query() ;
QueryRun qr = new queryRun(query) ;
QueryBuildDataSource qbds = qr.query().addDataSource(tableNum(SalesLine)) ;
QueryBuildRange qbrSalesId = qbds.addRange(fieldNum(SalesLine,SalesId)) ;
QueryBuildFieldList qbfl = qbds.fields() ;
;
qbrSalesId.value('SO-I-012482');
//The below 4 lines is to use group by
qbds.orderMode(OrderMode::GroupBy);
qbfl.addField(fieldNum(SalesLine,SalesQty),SelectionField::Sum);
qbfl.addField(fieldNum(SalesLine,SalesQty));
qbds.addSortField(fieldnum(SalesLine,Name));
//The below 2 lines is to use order by
//qbds.orderMode(OrderMode::OrderBy);
//qbds.addSortField(fieldnum(SalesLine,ItemId));
if (qr.prompt())
{
while (qr.next())
{
_salesLine = qr.get(tableNum(SalesLine));
a = a + 1 ;
print _salesLine.SalesId,'-----',_salesLine.ItemId,'-----',_salesLine.Name,'-----',a ;
}
}
pause;