web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested answer

How to create a computed field with the value coming from a display method

(1) ShareShare
ReportReport
Posted on by
Hi guys,
 
To provide you some context, I have a form AMDeviceTable in which i have displayed a field coming from a display method that was created under the AMDeviceTable table class extension, please see below:
 
// Display method to extract year from Date
    [SysClientCacheDataMethodAttribute(true)]
    display HERoutYear HERoutYear()
    {
        AMDeviceTableMaster deviceTableMaster;
        // Get the current record's
        deviceTableMaster = this.AMDeviceTableMaster();
        // Check if DeRegistrationDate is available
        if (deviceTableMaster.DeRegistrationDate)
        {
            return int2str(year(deviceTableMaster.DeRegistrationDate));
        }
        // If DeRegistrationDate is empty, check EndDate in AMRentDevice
        else if (this.rentalEndDate())
        {
            return int2str(year(this.rentalEndDate()));
        }
        // If both DeRegistrationDate and EndDate are empty, check HerEstimatedRentEndDate in AMDeviceTable
        else if (this.HerEstimatedRentEndDate)
        {
            return int2str(year(this.HerEstimatedRentEndDate));
        }

Additionally, i wanted to expose this field on my data entity AMDeviceOverviewEntity. Therefore, i have created a virtual field and called my display method result under the postLoad() method on the entity (as stated in MS documentation). However, virtual fields do not allow filtering in Excel OData. After some research i found on MS documentation that i should use computed fields instead but i am not able to achive that goal. I tried the below code but i am getting a build error.
 
        str fldMyField = SysComputedColumn::returnField(tableStr(HERDeviceOverviewEntity),
        tableStr(AMDeviceTable), methodStr(HERAMDeviceTableDbt_Extension, HERoutYear));
       
        return fldMyField;
 
Could you please help me fixing the issue?
  • Suggested answer
    Martin Dráb Profile Picture
    on at
    How to create a computed field with the value coming from a display method
    This is impossible. A computed column method is used to generate SQL code; the display method does nothing like that and it can't be called from SQL either.
     
    You'd have to rewrite X++ code of HERoutYear() to SQL and then write a computed column method generating this SQL code.
  • Suggested answer
    Bharani Preetham Peraka Profile Picture
    on at
    How to create a computed field with the value coming from a display method
    As you are using some functions in x++, this display method cannot be used directly in computed field. I would suggest to write a batch job, create some field and populate that field with batch job code based on this display method and use that in entity.
  • FS-16071301-0 Profile Picture
    on at
    How to create a computed field with the value coming from a display method
    Thank you so much for the reply, it makes total sense. Since the value was being correctly displayed on the data entity when i used the virtual field approach is there any workaround to make the filtering of this field work in Excel Odata?
  • André Arnaud de Calavon Profile Picture
    on at
    How to create a computed field with the value coming from a display method
    Hi Francisco,
     
    You can't filter on a virtual field if it is filled using the postLoad function. The data is already retrieved from the database before this method is executed. Like mentioned by Martin, you would need to rewrite it to SQL or filter the data using Excel worksheet options after refreshing the data. 

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans