Monday, May 18, 2015

SourceTableView Filters vs Manual Coding Filters

In Microsoft Dynamics NAV you can set the filters in two main different ways,
01. By using the SourceTableView Filter
02. By using the Setfilter or Setrange in the coding level. 

What has the higher preceding? Have you ever tried?

In order to check this I have created a new page. 
Source Table : Gen. Journal Line (81)

It shows all the available records in the Gen. Journal Line. 



In the OnOpenPage trigger I add the following filter code. This code will filter the page Rec to provided document number. 



As you can see page Rec has filtered to our given value, and also under the page filters it shows the current filters. Addition to that you will have the ability to remove or change the filter as your wish. 


To check the SourceTableView filters I have removed the previous code and add the following filters in the page properties. 


When I run the page with the new modification, it also get filtered to the provided value, but one thing to notice is you will not be able to clear the filters and will not show the current filters as well.   
This is not what we wanted to check, to check which filters have the higher proceedings, I have put both the filters to the page. 

Below is a screenshot of the result page. 

No records in the page, yet page filter shows it has filtered to the document number "SLI-CUS-15-00033". This is the document number we have provided in the OnOpenPage trigger. So something is going on in the background, to understand that I have cleared the filter which was applied for the document number "SLI-CUS-15-00033".

As I clear the filter for the document number "SLI-CUS-15-00033", page showed a one record. This is the document number we have given in the SourceTableView Filters.

What is happening in the background?
As soon as you run the page, Microsoft Dynamics NAV will filter the rec depending on the filters you have set in the SourceTableView property. After that only page will go through the code that has been written in the OnOpenPage trigger or any trigger available. 
Beauty of this is even if you have filters for the same fields (in this scenario Document Number), Microsoft Dynamics NAV will set the manual filters on top of the SourceTableView property.

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

5 comments:

  1. Thanks Tharanga for sharing this...

    ReplyDelete
    Replies
    1. Your welcome. Hope it was informational for you.

      Delete
  2. thanks tharanga for this information

    ReplyDelete
  3. Thanks for this.
    I was trying to apply the same concept to the Customer table.
    As I was wanting to the Balance (LCY) to Credit Limit (LCY) unfortunately, it was not liking the comparison and was throwing a decimal error:

    WHERE(Balance (LCY)=FILTER(>Credit Limit (LCY)))

    Do you have any suggestions?
    Thanks

    ReplyDelete