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

Announcements

News and Announcements icon
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 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?
I have the same question (0)
  • Suggested answer
    Martin Dráb Profile Picture
    240,538 Most Valuable Professional on at
    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
    3,634 Moderator on at
    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
    10 on at
    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
    306,887 Super User 2026 Season 2 on at
    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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders

These are the community rock stars!

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

#1
Martin Dráb Profile Picture

Martin Dráb 341 Most Valuable Professional

#2
CU10121822-0 Profile Picture

CU10121822-0 304

#3
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 283 Super User 2026 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans