Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

View - computed column

(0) ShareShare
ReportReport
Posted on by 455

Hi,

I am trying to compute a field for a View I created. I had a display method on the datasource of a list page but since filtering/sorting is not possible on the display method field I am creating a view. Since this is the first time I am creating and using a view I am not sure how to achieve the following.

I want the ItemId of the InventSum table passed to my method and then in the method the select statements queries some tables based on the itemId and return either boolean true or false based on some criteria. I did it easily in a display method but not sure how to do it via Views. Any guidance will be appreciated,

*This post is locked for comments

  • Samy123 Profile Picture
    455 on at
    RE: View - computed column

    Thanks Martin for your guidance. I admit I did not have complete understanding of Views when I started this thread but now I have enough knowledge and tools to address my issue. Thanks once again.

  • Verified answer
    Martin Dráb Profile Picture
    233,464 Most Valuable Professional on at
    RE: View - computed column

    It seems to me that you still don't understand how computed columns work. Let me address you argument and explain why they aren't valid.

    A. Computed columns return pieces of SQL code, which are written as text. It doesn't mean in any way that such code must return string values. X++ is written as text too and it still can use types such as numbers and classes.

    B. You're right that it must be valid T-SQL code, so... are "Yes" and "No" valid T-SQL code? Why don't you fix it if you already know that your code is wrong?

    Implement a method that returns a piece of SQL code defining the column. According to your requirements, it should return either 0 or 1, depending on some logic. Then create an Enum Computed Column, set your method's same to ViewMethod property and NoYes to EnumType.

    You gave it up before you actually started.

  • Samy123 Profile Picture
    455 on at
    RE: View - computed column

    Yes I have gone through that useful walkthrough, The problem was that I was trying to achieve the same result that I am getting through my display method i.e based on the value of itemId of the inventSum datasource I determine the return boolean value of that display column through couple of joined queries that I wrote in my display method. It turned out to be kind a not possible via the computed column of a view because

    A. I can only return str from a static server method of the view

    B. Even I return str "Yes" "No" when I synchronize the view it fails because I think It expects a valid T-SQL syntax as return string and so it says cant create the view invalid column name 'No'

    I think I need to try the other solution of going through the datasource and store the resulted true false in a temp table and adding that to the form datasource.

  • Martin Dráb Profile Picture
    233,464 Most Valuable Professional on at
    RE: View - computed column

    OK, so what's the problem? Have you already look at Walkthrough: Add a Computed Column to a View [AX 2012] and blog posts about computed columns (e.g. this and this)? If you have no idea where to start, you really should do it.

    Or do you have a particular problem? Then please explain it to us.

    You should use DictView.computedColumnString() to refer to the field, e.g. for using it in a WHERE clause.

  • Samy123 Profile Picture
    455 on at
    RE: View - computed column

    Oops that's my mistake. I am on AX 2012 R3.

  • Martin Dráb Profile Picture
    233,464 Most Valuable Professional on at
    RE: View - computed column

    You've tagged your question with AX 2009, which unfortunately doesn't support computed columns. Therefore you can't do it in this way.

    Depending on what your display method does, you might be able to rewrite it to a query. If not, you have to run your code in X++ - either you store the computed value as a regular field (and make sure you update it when needed), or you'll fetch the data before displaying in your form, calculate values, put it all into a temporary table and use this temporary table as form datasource.

    Or maybe it's all more complicated (= expensive) than the benefit of filtering by this value and users will rather live without it.

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

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Microsoft Dynamics AX (Archived)

#1
Mohamed Amine Mahmoudi Profile Picture

Mohamed Amine Mahmoudi 100 Super User 2025 Season 1

#2
Community Member Profile Picture

Community Member 48

#3
shanawaz davood basha Profile Picture

shanawaz davood basha 6

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans