Skip to main content

Notifications

Announcements

No record found.

Finance | Project Operations, Human Resources, ...
Suggested answer

Data entity view method not returning a value

Posted on by 64

I have a custom data entity, and I want to create a new field containing a product's height in centimeters (data entity will contain both inches and cm). I created a data entity view method called "displayEachHeightCm"). This view returns a conversion if I hardcode something into the UnitOfMeasureConverter method (ex.,UnitOfMeasureConverter::convert( 12345), ), but when I try to pass the current item (gathered from SysComputedColumn::returnfeidl), displayEachHeightCm always returns 0. 

Anyone have suggestions on what I'm missing to pass the right value in into the converter?

pastedimage1582325968838v1.png

  • Ludwig Reinhard Profile Picture
    Ludwig Reinhard Microsoft Employee on at
    RE: Data entity view method not returning a value

    Hi,

    Is this question related to D365FO?

    Best regards,

    Ludwig

  • Suggested answer
    Martin Dráb Profile Picture
    Martin Dráb 230,214 Most Valuable Professional on at
    RE: Data entity view method not returning a value

    This is a common mistake that we've discussed here many times.

    Your understanding of computed columns isn't correct. A computed column method isn't used to return a value; it returns a piece of T-SQL code for the calculation. The method is executed on database synchronization (when the underlying view is written to database) and the piece of T-SQL code is inserted to the view definition.

    If you want to use computed columns, your first step should be preparing SQL code that you want to generate. You obviously can't use X++ classes (such as UnitOfMeasureConverter) in SQL, therefore you'd have to rewrite the logic.

    If you want to use X++, you can use a virtual field (calculated in postLoad() method). Virtual fields are slower, you can't use them in DB queries etc., but this is their benefit.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans