web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Unanswered

How can I set the sort order on a field on a grid in a form

(0) ShareShare
ReportReport
Posted on by 4,079

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?

I have the same question (0)
  • BillurSamdancioglu Profile Picture
    21,233 Most Valuable Professional on at

    Hi,

    You may sort the form from grid and then save the form and apply for all the users?

  • Rudi Hansen Profile Picture
    4,079 on at

    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.

  • Alex VN Profile Picture
    1,994 on at

    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.

  • Rudi Hansen Profile Picture
    4,079 on at
    [quote user="Alex VN"

    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.

    [/quote

    Good 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.

  • Alex VN Profile Picture
    1,994 on at

    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,

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Abhilash Warrier Profile Picture

Abhilash Warrier 658 Super User 2026 Season 1

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 632 Super User 2026 Season 1

#3
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 570

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans