Saturday, February 26, 2011

Caching the display methods on Forms in AX 2009

AX Forms with many display methods might have some performance issues. To increase the performance of these kinds of AX forms, the display method written in the table methods need to registered for caching.

When the cached method is registered for caching then they perform calculations on fetched data, and then the calculated values are passed to the client together with the data. The calculated values are refreshed on reread. By default, the values are also refreshed on write and create.

A display method can be registered into cache by the following way:

  1. Locate the form that the method is used on.

  2. Expand the Data Sources node.

  3. Right-click the data source that the method is associated with, and then select Override Method > init.

  4. Call the this.cacheAddMethod method after the call to super() in the init method.

    The first parameter for cacheAddMethod determines the name of the method to be cached. The second parameter (set to true by default) determines whether the value of thedisplay method is updated when a record is written to the database.

    The example is as follows:

    public void init() 
    {     
     super();     
     this.cacheAddMethod(tablemethodstr(SalesTable,customerName)); }
    The above method has been overridden in the SalesTable dataSource's init() method. So, by adding this method, this method will registered into client cache and thus the performance of the form with display methods will be increased.

    Note : Only table display methods can be cached. Display Methods written on the form or the form data source cannot be cached and also edit methods cannot be cached.

No comments: