Tuesday, January 20, 2015

How to set/change the default sorting order of a page in Microsoft Dynamics NAV

Over the past few weeks I noticed there were several forum queries regarding how to sort a page with a different key. So thought to write a small blog post about how to do.

As the example I would take customer ledger entry page in Microsoft Dynamics NAV 2015. As you see in default system set the "Entry No." as the default sorting key. 

How system works and how did system identify the default sorting key. 
In Microsoft Dynamics NAV developer can set the sorting key in the page itself. If the sorting key is not set in the page level then system set the page sorting order depending on the primary key of the table. 

Why to set a default sorting key when user can set the sort order by clicking the header the column (Caption). 

Yes, It is true that user can set the sorting order by himself, but it is a manual process and every time user open the page he/she should be click on a column to set the sort key. So why not set a default sort key, because it save the time, and computer resource. 

Let's start with the tutorial. 


In this case I want to set Customer Ledger Entry page default sorting key as Posting Date. 

In order to perform this I want to have a active key in the source table. In this case my source table is Cust. Ledger Entry table. 

So I design my Cust. Ledger Entry table in the development environment. 


Then go to Tools -> Keys
It will open a window like below, and in the last line I add my new key, which is the Posting Date. 

After adding the key to the table I saved and compiled my Cust. Ledger Entry table. 

We are done with the table modification and now we have to set the key to the page. In order to do that I have to open the Customer Ledger Entries page in the development environment. 

Below how it look like once you open the page in the design view, Click on the first empty line of the page design view. 

Then click on the properties icon in the top toolbar. By doing that system will open a properties window of the page. 
Remember this is where many of the new developers make the mistake. In order to get the page properties you need to click on a empty line and then click on the properties. 
If you click on any other row and then click properties will open the properties of that particular row. 

Once you click on the Page property following screen will open. First check the Name field in the list. It should be as the page Name and if the name field has a different name than the page name, that means you must have opened a property of a field. 

In the following page as you can see source table is set as the Cust. Ledger Entry and Source Table View is empty. That means system will get the sort key from the source table. In this case Entry No. 
So we want to change it to Posting Date. 
To do that click on the drilldown button in the SourceTableVeiw.

Once you click on the SourceTableVeiw  drilldown system will open up the following window where you will be able to set your key for the page. 

As the window below set the key and set the order you want to have. 
When you click on this it will show all the active keys for the page and you have to select your key. In this case I will select Posting Date as my key.  

Once you click on the OK button, window will get closed and SourceTableVIew field will be filed with the key and the order you sorted in the previous window. 
Esc. from the properties window and then compile and save the page. 

We are ready to go. To check the modification, open the page in RTC and as you can see default sorting is set to the Posting Date. 

Please provide your feedback with a comment. 
Thank you and Regards,
Tharanga Chandrasekara

1 comment:

  1. Hi thanks for a fine blog
    I sort on the posting date descending because i want to see the current postings and not what happent 2-3 years ago :-)

    But after sorting descent the form opens on the oldest record still? (at the button of the screen)
    I found that

    ReplyDelete