0% found this document useful (0 votes)
65 views6 pages

Display Method in D365 F

A display method is a method used to display data from another table or source on a form or report. It appears like a normal field but does not actually exist as a physical field in a table. Display methods can be created on tables or form datasources and must use a specific signature depending on where they are declared. They allow retrieving and displaying related data but have limitations like not supporting filtering or sorting. Caching can improve performance for complex display methods.

Uploaded by

Saumya Dwivedi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
65 views6 pages

Display Method in D365 F

A display method is a method used to display data from another table or source on a form or report. It appears like a normal field but does not actually exist as a physical field in a table. Display methods can be created on tables or form datasources and must use a specific signature depending on where they are declared. They allow retrieving and displaying related data but have limitations like not supporting filtering or sorting. Caching can improve performance for complex display methods.

Uploaded by

Saumya Dwivedi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Display Method in D365 F&O

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.

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;
}
else
{
return _custPackingSlipTrans.Remain;
}

} </xpp>

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

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> public void init() {


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

} </xpp>

Example

Create a Table Employee with field Employee Id

Also create relation with HcmWorker Table

Create New Method on Table Level – to print employeeName


Write Code

display Name employeeName(EmployeeTable _this)


{
HcmWorker hcmWorker;
DirPartyTable dirPartyTable;
DirPerson dirPerson;
select firstonly PersonnelNumber from hcmWorker where hcmWorker.PersonnelNumber
== _this.EmpId;
select firstonly RecId from dirPerson where dirPerson.RecId == hcmWorker.Person;
select firstonly Name from dirPartyTable where dirPartyTable.RecId ==
dirPerson.RecId;

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

Run the form by using Display Menu item

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy