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

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

AX2012 R2 Sort Order on a Form Grid

(0) ShareShare
ReportReport
Posted on by

I created a Form that I want to have a special order when it populates.

I first created a View that has a couple Computed fields in it.  One is called SortNode.

That View is called by a Query - which is Ordered By SortNode.

I then use the Query in another View since I am joining a few different tables.

But for some reason the sort order of the data that populates the form is by the original files tables index (HierarchTreeTable-HierarchyElementNumbIdx).

How do I get the Form to show the data in the order that I have it in the Query and not use the index.  Or, is there some way to create an index for the View so I can tell the grid to use that index?

*This post is locked for comments

I have the same question (0)
  • Community Member Profile Picture
    on at
    RE: AX2012 R2 Sort Order on a Form Grid

    I did some more research and finally found how to set the sort.

    Created these two methods for the Data Source ccv_HierTreeTable (the view I use for the form).

    public boolean modified()

    {

       boolean ret;

       ;

       ret = super();

       HierTreeTable_ds.executeQuery();

       return ret;

    }

    public void executeQuery()

    {

       ccv_HierTreeTable_ds.query().dataSourceNo(1).sortClear();

       ccv_HierTreeTable_ds.query().dataSourceNo(1).addSortField(fieldNum(ccv_HierTreeTable,SortNode),SortOrder::Ascending);

       super();

    }

    The only problem I have is that the Modified Method did not compile because it says that [Super() not allowed here.] - but it still works.  

    Can anybody answer these three+ things?

    1) why is super() not allowed in the Modified Method (what does super() do)?

    2) why does it still work if I don't have my Modified method calling the ExecuteQuery method?

    3) why do I need the _ds after my view name?  What is that all about?  

    ---all these little important pieces of knowledge and I don't know where to find documentation that explains what is going on -- I know to do them now, but not why, and not knowing why really bugs me!!!

  • Verified answer
    Martin Dráb Profile Picture
    236,297 Most Valuable Professional on at
    RE: AX2012 R2 Sort Order on a Form Grid

    1. super() is used to call an implementation of the same method in the parent class. Form data source doesn't have any modified() method, therefore you can't call it.
    2. The query executes automatically (unless you disable it on the data source).
    3. ccv_HierTreeTable_ds is an automatically created variable representing the form data source. ccv_HierTreeTable represents the actual record.
    4. Add the sorting in the init() method, not in executeQuery(), unless you want to prevent users from sorting by any other field.
  • Community Member Profile Picture
    on at
    RE: AX2012 R2 Sort Order on a Form Grid

    Thanks Martin.  I am beginning to get the hang of a little bit more every time I try something new.   There is so much to learn, and all these little pieces that it is hard to find information on.  

    As for the sort order - I will try to figure out how to add the sort to the init() - anything you can point me to so I can read up on it?  For this project, they won't need to sort it by any other column, just be able to filter, so I should be fine.  

    I don't know what I would do without this Forum.  You - and all the others that take time to help us newbie's out are doing a great job.  Thanks!

  • Martin Dráb Profile Picture
    236,297 Most Valuable Professional on at
    RE: AX2012 R2 Sort Order on a Form Grid

    You're welcome. :-)

    There is nothing difficult in moving the code to init() method of the data source. Just cut it from executeQuery() and paste it to init() below super(). The difference is that init() is called just once, when the form starts, while executeQuery() runs more often - including the case when a user tries to add his own sorting.

    Event Method Sequences in Form Scenarios might help you a little bit.

    By the way, try to replace ccv_HierTreeTable_ds.query().dataSourceNo(1) with this.queyBuildDataSource(). It does the same but it's more readable.

  • Community Member Profile Picture
    on at
    RE: AX2012 R2 Sort Order on a Form Grid

    Hi Guys,

    I have also get some useful info from this page. 

    Thank you very much for your sharing...

    Especially Martin..

  • Michel Chacaliaza Profile Picture
    104 on at
    RE: AX2012 R2 Sort Order on a Form Grid

    Thanks, Good contibution!

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Community Member Profile Picture

Community Member 4

#2
Guy Terry Profile Picture

Guy Terry 2 Moderator

#2
Nayyar Siddiqi Profile Picture

Nayyar Siddiqi 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans