Contact Me

Total Pageviews

Sunday 21 September 2014

Display methods in Axapta

A display method can be created on either a table (in which case it is available for all forms using that table), or on the datasource of a specific form (in which case it is available only on that form).
Display methods must be created using a specific signature, which varies depending on the location of the method.

Display methods on tables :

When declared on a table, display methods must be preceded with the keyword display and expect no parameters. The following example is a standard display method from the SalesTable table.


<xpp> display CustName customerName() {
   return this.partyTable_CustAccount().Name;
} </xpp>

Display methods on form datasources :


When declared on a form datasource, display methods must have one non-optional parameter.The parameter is a buffer of the same type as that of the datasource on which the method is declared. It is essential as, when viewing a grid on a form, the method must know for which row the return value is to be calculated.

As an Example consider the "ProjTransRevenue" form.It contains "ProjRevenueTrans" as it's datasource.I have a customized method "jss_categoryName" which is a display method.


 

display CategoryName jss_categoryName(ProjRevenueTrans _projRevenueTrans) //datasource parameter
{
   return CategoryTable::find(_projRevenueTrans.CategoryId).CategoryName;
}

  
Caching :

One significant side-effect of using display methods can be the impact on performance.To alleviate this, display methods on tables can be cached by using the cacheAddMethod method of the datasource object. To enable caching of a display method, call cacheAddMethod() from the init method of the datasource. This ensures that the display will only be calculated when necessary and can result in a significant performance improvement.

<xpp> public void init() {
   super();
   // Enable caching of the document handling display fields
   dirPartyTable_ds.cacheAddMethod(tablemethodstr(DirPartyTable, showDocHanIcon));
} </xpp>

Happy Daxing:)

2 comments:

  1. Thank you so much for explaining this, that's the exact issue with my ax dynamics I had a couple of days ago and I had no idea how to fix it. You're awesome!

    ReplyDelete
  2. i think that is a great display method in Axapta.. i would like to learn more about it.. please add more content on this site.

    ReplyDelete