Caching Display Methods

Rumman Ansari   Software Engineer   2024-07-10 06:04:37   143  Share
Subject Syllabus DetailsSubject Details 5 Questions Login to Open Video
☰ TContent
☰Fullscreen

Table of Content:



In Dynamics 365 for Operations, we don’t have the option to create methods on table extension, so we should use the extension class to do that.

In this article, we will see how to create a display method on the table extension class and use it on a form extension.

First, create your table extension class and your display method following the example below: In this case, I took an example of the HcmJob table and I want to create a job id + description display field

Example


Public static class HcmJob_Extension
{
    [SysClientCacheDataMethodAttribute(true)]
    public static display Description jobDescription(HcmJob _this)
    {
        return  strFmt("%1-%2",_this.JobId, HcmJobDetail::findByJob(_this.RecId).Description);
    }
}

 

To use your display method on the form, create your new string control on the form extension and use the property as below:

Caching Display Methods
Figure: Caching Display Methods

To cache your display method on the form set on the field the property “Cache Data Method” = yes if you don’t want to use the Attribute above.

 

That’s it! We are done with the new display method. Build/ sync your project and check with a new form.

Old Way Of Caching A Method

In order to cache the display method, first override the ‘init’ method on the form.

Next, add the a line of code in this format:


<Data Source Name>_ds.cacheAddMethod(tableMethodStr(<TableName>, <Display Method Name>));

For example, there is code on the CustTable form, to cache the edit method named ‘phone’. It is found in the ‘init’ method. It looks like this.


custTable_ds.cacheAddMethod(tableMethodStr(CustTable, phone));

The code uses the method cacheAddMethod on the form Data Source. The name of display method is passed into the method. The code uses the global function ‘tableMethodStr’ to get the name of the method. This global function takes the name of the table, and the name of the method as parameters. This is useful, because if the name of the method ever changes, a compile error will be thrown until this code is changed. Whereas a hard-coded string would only fail at runtime.

Please see additional Microsoft documentation here.