Announcements
I have a problem with sorting lines in a Grid on a form in D365FO.
The form is not a standard form but one made custom for our solution.
And the problem is that since we need to sort on a field in the Grid that is a Reference Group field, and because of that it was not possible to sort on the data source.
But we found that it was possible for the user to sort on that field in the client by choosing "Sort A - Z", and from that we found that from code we could call the .Sort method on the field with parameters SortOrder::Ascending
But it was not really clear where the best place was to call the .Sort method, so to start with it was placed in the task method on the form that was already used, and that did seem to work.
But if the user then edits some data in the form and press the save button, then the Sorting seems to go back to the old sorting.
So our problem is where should we place the call to the .Sort method to make sure it works?
Hi,
In this case I think it would be better to check for that datasource query to make it persistent, and then you might add sort order to the query instead of calling the sort method on the datasource as the sort method might call active method and get stuck in infinite loop.
You might refer to this article:
community.dynamics.com/.../dynamics-ax-2012-form-datasource-sort-x
Regards,
Hi,
If you want it to be persistent I think you can try to do the sort on respective Datasource - Active method, which will be called everytime you change the record cursor.
Regards.
[/quoteGood sugestion, but when I do that it seems to get caught in a loop where the active method is called again and again.
So it would seem that calling the Sort method on the field then also makes the form call the active method again.
I did try checking the value of the Sort before setting it like this:
if(RetailGroupMemberLine_Product.sort() != SortOrder::Ascending) { RetailGroupMemberLine_Product.sort(SortOrder::Ascending); }
But it still keeps calling the active motode in a loop.
Hi,
If you want it to be persistent I think you can try to do the sort on respective Datasource - Active method, which will be called everytime you change the record cursor.
Regards.
No I need a code solution for the problem, like where do I call the .Sort method so it will always be active on the field.
Hi,
You may sort the form from grid and then save the form and apply for all the users?
André Arnaud de Cal...
294,255
Super User 2025 Season 1
Martin Dráb
232,984
Most Valuable Professional
nmaenpaa
101,158
Moderator