D365 Display method

In Microsoft Dynamics 365 F&O we can show data on a form that is not directly in that data source of the form but is linked to that data source somehow. Let’s Just say in Purchase Order form we can get the vendor ID but to get the vendor group we need to add the vendor table in the purchase order form. In this case instead of adding another data source we. an just add a display method on the form level or table level.

Also in some scenarios, data is dynamic which means it is not stored in any table and we need to generate it dynamically. In that case, we create a display method on the table level or form level. so basically we can create a display method on the table level and form level. Usability decreases when creating a display method on form since the scope of that display method is within that form only. but in the case of a table usability is better since the scope of that display method is in all the forms of that table.

Limitation of D365 Display method:

1. We can’t filter data in the display method field.

2. Data generates dynamically hence it puts a load on the form.

Benefits of the D365 Display method:

Gets user-expected data no matter the complexity between the relation of and tables.

Example of D365 Display method:

  1. String
  2. Logical
  3. Number/Amount

1. Example of String in D365 Display method:

[ExtensionOf(tablestr(ForecastItemAllocationLine))]
final class ForecastItemAllocationLineTable_Extension
{
    [SysClientCacheDataMethodAttribute(true)]
    public static display ItemName itemName(ForecastItemAllocationLine _this)
    {
        return InventTable::find(_this.ItemId).itemName();
    }

}


2. Example of Logical in D365 Display method:

[ExtensionOf(tableStr(LedgerJournalTrans))]
final class LedgerJournalTrans_Extension
{
    [SysClientCacheDataMethodAttribute(true)]
    public display NoYes LSApproved()
    {
        if(this.CashDiscAmount > 1000)
        {
            return NoYes::Yes;
        }
        else
        {
            return NoYes::No;
        }
    }
}


3. Example of Amount In D365 Display method:

[ExtensionOf(tableStr(LedgerJournalTrans))]
final class LedgerJournalTrans_Extension
{
    [SysClientCacheDataMethodAttribute(true)]
    public display Counter LSLastFileNumber()
    {
        VendPaymModeTable   VendPaymModeTableLocal;
        select firstonly LastSequenceNumber from VendPaymModeTableLocal
            where VendPaymModeTableLocal.PaymMode == this.PaymMode;
        return VendPaymModeTableLocal.LastSequenceNumber;
    }
}

Once this is done just apply the method on the Data method property of the form control.

How to Cache D365 Display method:

We can also cache a display method so that load on DB is one time, only when the form is loaded first time which makes the performance of the form better.

[SysClientCacheDataMethodAttribute(true)]

We just need to add the above code, above the d365 display method.


You can also check out my previous blog: Create a custom service in d365 FO

Need help? Connect Atul

Atul Yadav
Latest posts by Atul Yadav (see all)

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *