A clarion call for building frameworks in Dynamics AX

In Dynamics Ax 2012 filter fields are provided as standard on list pages, as highlighted in the screenshot below: –

 

ListPage

 

This filter functionality is not provided as standard on Detail forms. As part of the new Bank Reconciliation functionality developed by K3 Retail I have implemented a new framework to make it easy to add filter fields to detailforms; as shown in the screen shot below: –

 

BankRec

 

Whilst we could have implemented this as a one off change to the form in question, building a reusable framework just made more sense because we can then re-use this functionality time and time again. This saves time for future developments and makes maintenance of the software easier and more cost effective. This is an excellent example of the power of Dynamics Ax 2012 object oriented development.

Our new framework is provided by a new class (called K3FormFilterControls) that automatically adds the standard buttons for “Filter by selection”, “Filter by grid”, “Advanced filter/sort” and “Remove this filter” to the form at run time.

To give you an idea of how effective a framework like this can beI thought I would simply describe the modifications to the form that are required to implement our framework: –

1. Create a field group (set auto declare to Yes) to contain the filter fields and buttons

The class K3FormFilterControls will automatically add the fields and buttons at run time for you.

2. Declare a variable in the form class declaration of type K3FormFilterControls

3. Amend the Init method of the form to instantiate the K3FormFilterControls object.

The construct method takes parameters for such things as the form run instance object, datasource, and the field group display control (see point 1 above).

4. If you require additional actions to be carried out on the form in response to filters being applied then you can add the following methods to the form which will then be called by the filter control object framework. For example ApplyFilter and RemoveAllFilters.

The above point, ensures more complex filter controls can be designed into a form whilst retaining the benefits of the new framework. For example in our Bank Reconciliation form we have designed specialised filters to enhance the matching process that work in conjunction with the standard filters provided by the new framework. The screenshot below shows the key filters: –

 

BankRecForm

So, you can see that investing a little extra time during the development cycle can make a huge difference in how useful your code is and can reward you with huge time savings in the future. The power of AX is there for you to use so make the best of it!