Wednesday, May 22, 2013

Dynamics AX 'CacheAddMethod' functionality made easy

Took a lot of time off from programming and forgot how to do small things like cacheaddmethods. Not something I do all the time in the functional realm (duh!). All the posts around this I found online were all saying the same thing. This is my cheat sheet for this. New content on the web is never a bad thing.

This post will take the assumption that we are creating a new display method and referencing it to an existing form. So basically showing beginning to end stuff.

Note: Using cacheAddMethod for a field will not allow you to filter this field; it is display/informational only
Note: Using cacheAddMethod can cause the grid functionality to move slower so be cognizant of using this in excess.
  1. Create a display method on the table that is the datasource on the grid of interest (could be primary). For instance, if the grid in the form was showing sales line information, we are going to create a new method on the table (not the form or datasource; the table itself). It might look like the below in Figure 1. It can have whatever in it but it will need to return something. This will be the value you see in the grid
  2. Reference this display method on the form's datasource's init method after the super. See Figure 2 below. Notice the use of 'tableMethodStr'. The first parameter is the table that we added a method to in Step 1 and the second parameter is the display method name we created from Step 1.
  3. Add a field (of the correct data type) to the grid. Reference the correct datasource and put hte name of the table method added in Step 1. See Figure 3 below.
public display salesQty daxSalesQtyReferenced()
{
    return this.InventTransId ? this.invoicedInTotalServer() : 0;
}
Figure 1 - Display method on the table
void  init()
{
    ;

    super();

    salesLine_ds.cacheAddMethod(tableMethodStr(SalesLine, daxSalesQtyReferenced));
} 
Figure 2 - The display method in the datasource of the grid after the super call 

Figure 3 - Add a field to the grid and referenced the new cached method in the DataMethod field

No comments:

Post a Comment