I have a table that is displayed in displayed in a form grid. The table contains the field MainAccountId, which is basically RecId of the system table MainAccount (there is a relation between the tables), but it's displayed on the form by the field Account Number (string value). The table also has the field CostCenterId, which is RecId of the OMOperatingUnit table (there is a relation between the tables), but on the form, the Cost Center code is displayed by using the Replacement Field Group. The client wants the records in the grid to be sorted by Account Number, and then by Cost Center Code. There is a thread where this was discussed, but the accepted solution explains how to sort data in GUI (at run time), whereas I need the records to be sorted when the user opens the form for the first time (or in other words - at design time). I have tried using QueryBuildDataSource class. by writing a code like this:
QueryBuildDataSource qbds = MyTable_ds.queryBuildDataSource();
qbds.sortClear();
qbds.addSortField(fieldNum(MyTable, MainAccountId),SortOrder::Ascending);        
qbds.addSortField(fieldNum(MyTable, CostCenterId),SortOrder::Ascending);
At first, I'm not sure whether QueryBuildDataSource supports sorting on multiple fields, but even if it does, this wouldn't work, because it wouldn't sort the records by the string values from their original tables (MainAccount.Name and OMOperatingUnit.OMOperatingUnitNumber), but by their corresponding RecId fields' values in MyTable.
Does anyone know how this sorting can be set during the design, through X++ code or through some form properties?