Display Method in D365 F
Display Method in D365 F
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.
Usage[edit]
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.
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.
return this.partyTable_CustAccount().Name;
} </xpp>
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.
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.
if (isVersionArchived)
{
return _custPackingSlipTrans.joinChild().Remain;
}
else
{
return _custPackingSlipTrans.Remain;
}
} </xpp>
Limitations[edit]
A display method behaves like an ordinary field but has some limitations:
If you need to sort and filter by a display method's data, there are the following workarounds
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.
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() {
} </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.
Caching[edit]
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>
Example
return dirPartyTable.Name;
}
To check Display Method working or not , create form then create a string type control and Name it as
EmployeeTable_EmpName and set its properties
Set DataSource and DataMethod Properties of string type Field