Search:

How to Create Custom Dynamic Filters and Use Dynamic Filters for Data Security


Data Security (16:56)
Adding Dynamic Filters (7:22)

Overview: At times it may be desirable to filter data based on a changing value like "current year". Field Level and Data Security provides the ability to set up Dynamic Filters to accommodate this scenario.

You also have the ability to add your own custom filters with just a few lines of code. This requires a developer license and should be performed by a developer with knowledge of the NAV development environment. More information is provided below.

For more information on Data Security Codes see the following How-To document:

How To Create a Data Security Code

First, let's see how to use a Dynamic Filter.

1) Add a new Data Security Code to filter flowfields on the G/L Account table to current year transactions. From the menu select Data Security Codes and click New. Enter Source Table ID 15 and code CURYR. On the line for Page 0, drill down on Fields.



2) Add a line for Field ID 28 and select Filter Type Editable. Enter checkmarks in the Substitute Filter Value and Always Substitute Filter Value fields. Click the Assist Edit on Filter Value. The lookup shows the list of standard dynamic filters provided as part of the Field Level and Data Security product.



3) Select Year for the Filter Value.



4) The Filter Type of Editable means the filter can be seen and be removed by the User. The Filter Type of Hidden means the filter can't be seen, therefore it can't be removed by the User.

5) When the Always Substitute Filter Value field has a checkmark and the Substitute Filter Value is also checked, the Data Security Filter is calculated every time the page is opened. Otherwise, if only the Substitute Filter Value is checked, the filter is only calculated the first time the page is opened. The Always Substitute field should be used if the data controlling the filter can change. The impact on performance is still insignificant.

6) This completes the setup of the Data Security Code using a Dynamic Filter. Click Ok.

Assign this Data Security Code to a User. The flowfields in the G/L Account table will be filtered to only the current year transactions. This will apply to all pages not otherwise specified, because we added the filter to the Page 0 line (default). For example, see that the Limit Totals in the Chart of Accounts show the date filter below. The filter can be seen and removed by the User because the Filter Type of Editable was selected when the Data Security Code was created. If the Filter Type of Hidden had been selected, you could not see the filter and therefore would not be able to remove the filter.



For information on setting up User Security, please see the following FAQ:

How To Create User Security Setup

Creating Custom Dynamic Filters

As mentioned above, it is possible to ADD custom Dynamic Filters. Although the Field Level and Data Security product comes with several standard dynamic filters, you also have the ability to add custom filters with just a few lines of code. The following will require a developer license and should be performed by a developer with knowledge of the NAV development environment.

1) The standard filters are managed in Codeunit 14123806 ES Dynamic Filter Management. In Object Designer, select the codeunit and click Design. Codeunit 14123806 should NOT be modified directly, since this would cause unnecessary complications with future upgrades.



2) The CalculateFilter function returns the value of the filter at runtime. These calculated values can be viewed by running page 14123832 ES Dynamic Filters from Object Designer.



3) Codeunit 14123814 ES Dynamic Filter Customize is provided expressly for the purpose of creating custom Dynamic Filters. In Object Designer, select codeunit 14123814 and click Design. A sample using the system TIME function is provided in the code. Remove the comments from the lines as shown below. The code should appear as in the screenshot below.



4) Save and compile the code

5) To set up and test the filter, run page 14123832 (ES Dynamic Filter), from the Object Designer. Use the Insert Filters from Codeunit Action to open the Live Objects window.



5) Select codeunit 14123814 ES Dynamic Filter Customize and click Ok.



The MyTime code was inserted automatically.



The custom filter can now be used for filter values in Data Security Codes. In this way, any number of custom dynamic filters can be added to the product.



Like   Don't Like

© 2024 Mergetool.com. All rights reserved.



Related resources

Download software from Mergetool.com