dynamics ax 2012 form datasource sort X++

Today I got requirement to insert record at run time and shows result in sorted order. I used following code code snippets. Suppose we are sorting on Customer
in required field

CusTable_ds.query().dataSourceNo(1).sortClear();

CusTable_ds.query().dataSourceNo(1).addSortField(fieldNum(CustTable, AccountNum), SortOrder::Ascending);
CusTable_ds.executeQuery();

alirazazaidi

Advisory software engineer, Software engineer, Last 4 years focus on Dynamics Ax 2012. MVP and Microsoft Certified trainer for Dynamics AX.