Skip to main content

Notifications

Announcements

No record found.

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 10
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?
  • André Arnaud de Calavon Profile Picture
    André Arnaud de Cal... 291,642 Super User 2024 Season 2 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. 
  • FS-16071301-0 Profile Picture
    FS-16071301-0 10 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?
  • Suggested answer
    Bharani Preetham Peraka Profile Picture
    Bharani Preetham Pe... 3,587 Super User 2024 Season 1 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.
  • Suggested answer
    Martin Dráb Profile Picture
    Martin Dráb 230,371 Most Valuable Professional 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.

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

Congratulations 2024 Spotlight Honorees!

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December!

Congratulations to our December super stars! 🥳

Get Started Blogging in the Community

Hosted or syndicated blogging is available! ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,642 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,371 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans