Sorting data in form datasource in MS Dynamics AX or 365 F&O

In Dynamics, to sort the data from the data source of a form you need to modify the init() method.
After super(), use the following code to sort by a field:

        /// <summary>
        ///	Ovveride init method
        /// </summary>
        public void init()
        {
            super();
            SalesTable_DS.query().dataSourceTable(tableNum(SalesTable)).addSortField(fieldNum(SalesTable, SalesId), SortOrder::Descending);
        }

It is also possible to sort by multiple fields as follows:

         /// <summary>
        ///	Ovveride init method
        /// </summary>
        public void init()
        {
            super();
            SalesTable_DS.query().dataSourceTable(tableNum(SalesTable)).addSortField(fieldNum(SalesTable, SalesId), SortOrder::Descending);

           SalesTable_DS.query().dataSourceTable(tableNum(SalesTable)).addSortField(fieldNum(SalesTable, DeliveryDate), SortOrder::Descending);
        }

Lascia un commento