Skip to main content



No record found.

Microsoft Dynamics AX forum

Add a computed field to entity

Posted on by 150

I have an entity with a field (LedgerDimension) that cannot be set to public, but need in my BYOD export. My idea is to clone it as a computed field.

According to the article below,

"it's easier to come up with the SQL definition in Microsoft SQL Server Management Studio (SSMS) before using it in X++."

The example shows T-SQL code after X++ Code, is it supposed to be included there? Can't I just edit the view directly from SSMS and add the computed column there?

  • agneum Profile Picture
    agneum 150 on at
    RE: Add a computed field to entity

    Great, computed column worked like a charm! Your solution was clear even even though I'm not a developer.
    To anyone else who might stumble on this thread who needs a quick guide on computed column:

    1) Create a new field in your entity of the type you need

    2) From the Entity, Rightclick method > New method

    3) Paste above code privoded by Pedro, rename the following:

    myField (to something that resembles the name of your new field)
    MyEntity (name of your entity)
    MyTable (name of the table listed under datasources)
    MyField (name of the field from the table you specified above. I think only private and public fields will show up in the intellisense, but can't confirm)

    Then, from your new field set isComputed property to "Yes" and DataEntityView Method  property to whatever you named your function to.

  • Suggested answer
    Pedro Tornich Profile Picture
    Pedro Tornich 955 on at
    RE: Add a computed field to entity

    Hi agneum,

    You have two options in this case.

    1) Create a virtual field, which must be filled with X code in the postLoad() method of your entity.

    2) Create a computed column, which is a SQL statement added to the view when you compile it. Computed columns are not filled at runtime like virtual fields, their logic resides on SQL just like if you added them directly from SSMS.

    Here is a sample code:

    private static str myField()
        str fldMyField = SysComputedColumn::returnField(tableStr(MyEntity),
            tableStr(MyTable), fieldStr(MyTable, MyField));
        return fldMyField;

    Like Satish mentioned, do not add the field directly from SSMS, because it will be dropped.

  • Suggested answer
    Satish Panwar Profile Picture
    Satish Panwar 14,639 on at
    RE: Add a computed field to entity

    Hi agneum,

    You can use either x++ or SQL in AX. Don't add computed column in SQL directly, it will get dropped during Synchronization.

Helpful resources

Quick Links

Replay now available! Dynamics 365 Community Call (CRM Edition)

Catch up on the first D365 Community Call held on 7/10

Community Spotlight of the Month

Kudos to Saurav Dhyani!

Congratulations to the June Top 10 community leaders!

These stars go above and beyond . . .


André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 288,420 Super User

Martin Dráb Profile Picture

Martin Dráb 225,672 Super User

nmaenpaa Profile Picture

nmaenpaa 101,148


Featured topics

Product updates

Dynamics 365 release plans