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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Add a computed field to entity

(0) ShareShare
ReportReport
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,


https://docs.microsoft.com/en-us/dynamics365/fin-ops-core/dev-itpro/data-entities/data-entity-computed-columns-virtual-fields


"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?

I have the same question (0)
  • Suggested answer
    Satish Panwar Profile Picture
    14,671 Moderator on at

    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.

  • Suggested answer
    Pedro Tornich Profile Picture
    955 on at

    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.

  • agneum Profile Picture
    150 on at

    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.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

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

#1
Martin Dráb Profile Picture

Martin Dráb 683 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 563 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 398 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans