Axaptapedia is now maintained by AgileCadence For more information please click here.

Display method

From Axaptapedia
Jump to: navigation, search


A display method is not a physical field in a table but rather a method of displaying information from another table or source. It appears like a "normal" field and it can be used in forms and reports. For more information about display methods go to MSDN.


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[edit]

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 datasources[edit]

When declared on a form datasource, display methods must have one non-optional parameter. The following example is from the PurchEditLines form in standard Ax 2012. 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.

<xpp> //BP Deviation documented display ImageRes backOrder(PurchParmLine _purchParmLine) {

   if (-InventTrans::backOrderQtyIssue(_purchParmLine.ItemId, _purchParmLine.InventDimId) > 0)
       return #Imageinfo;
   return 0;

} </xpp>

Retrieving data from linked form datasources[edit]

When using a display method on a form datasource, it's possible to retrieve values from table fields in other datasources which are linked through an inner join to the current datasource. This is doing using the joinChild method and is illustrated in the example below.

This is the only reliable way to retrieve data from a joined datasource in a display method.

<xpp> display public SalesQty remain(CustPackingSlipTrans _custPackingSlipTrans) {

   if (isVersionArchived)
       return _custPackingSlipTrans.joinChild().Remain;
       return _custPackingSlipTrans.Remain;

} </xpp>


A display method behaves like an ordinary field but has some limitations:

  • its data can not be changed (use edit method instead)
  • you can not filter and sort by display methods

If you need to sort and filter by a display method's data, there are the following workarounds

  1. Replace a display method with an ordinary stored field
  2. Replace a display method with inner joined table

The last is applicable if you have an often situation when display method simply returns a field value of the related table by mandatory field.

For example, you have a display method on the table named YourTable like the following: <xpp> //BP Deviation Documented display EmplName emplName() {

   return EmplTable::find(this.EmplID).Name;

} </xpp>

If YourTable.emplID is mandatory, you can use an inner join instead of this display method:

  1. Place additional datasource on your form for EmplTable.
  2. Set LinkType property to 'InnerJoin'
  3. Add 'Name' field of the created EmplTable datasource to your Grid control or wherever else

If your original datasource is read only, your job is done. In the other case, when you try to add a new record to the datasource, you will see an error about mandatory fields of EmplTable. This error occurs because Ax tries to save joined datasource. To prevent such behaviour, you should

4. Override the write method of the EmplTable datasource with an empty implementation to prevent writing data to the table <xpp> public void write() {

   // 'super' is commented out:
   // super();

} </xpp>

5. Override the validateWrite method of this datasource to prevent error messages: <xpp> public boolean validateWrite() {

   boolean ret;
   //ret = super();
   ret = true;
   return ret;

} </xpp>

Now you can filter and sort your datasource by employee full name.


One significant side-effect of using display methods can be the impact on performance. Particularly when complex methods are used to calculate values being shown on grids, a visible slow-down in form performance can be experienced. This is largely due to the fact that the methods are often run repeatedly even when no reason is apparent and the values are unchanged.

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() {

   // Enable caching of the document handling display fields
   dirPartyTable_ds.cacheAddMethod(tablemethodstr(DirPartyTable, showDocHanIcon));

} </xpp>