Hi all, I have a grid on a form (InventJournalCount), that the users wish to sort by the ItemID. Currently there is no sort on the grid. I understand that I need to use the AddSortField command, but I’m not sure where to put it (possibly the Init method on the Form). What do you think?
Ask yourself when it should and can run. It should run when you start the form, but it can’t run before the query is initialized. Therefore the first possible place is init() method of the datasource after super().
It could look like this:
this.queryBuildDataSource().addSortField(...);
Form’s init() method is another possible place.
In many cases, you can simply set Index property on the datasource and you don’t have to write any code at all.
Form always uses a query, if it has at least one datasource. Whether you add tables directly or from an AOT query isn’t important.
super() calls the kernel implementation of init(), which is where datasource get initialized. You have to first create datasources (super()) and only then you can modify them.
Thanks Martin. I added it after super(), saved and compiled (with no errors). I went back into the Counting Journal lines screen, and it is still sorted in the wrong order, so I must be doing something wrong. Do you think that my code is correct?
To debug a query, first look at the (pseudo)-SQL query string that you managed to generate by your code. For example, put info(InventJournalTrans_ds.queryBuildDataSource().toString()) after adding your sorting.
Thanks Martin! You’re a star! :o) The problem was that my order was set to descending instead of ascending. Once I changed that, everything worked as expected :o) Thanks again for your help!!