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

Sample of computed column using enums

(0) ShareShare
ReportReport
Posted on by 709

Hi guys,

Need your lead as I need to create a computed column with calculation depend on field enums. 

The case is :

In my data entity, which is the datasource is InventTrans, I have custom field named COGS, which I want to be filled in whenever the InventTrans is with StatusIssue::Sold and InventTransType::Sales. The value to be filled in is the CostAmountPosted in that InventTrans it self.

Question is how am I going to create it in computed column ? At least can someone lead me to a similar case in AOT (but with easy to understand, not a complex code). I've been creating some of this before but usually only relate to values or dates, so has not use field enums before ? 

Thanks in advance.

I have the same question (0)
  • Verified answer
    Martin Dráb Profile Picture
    237,882 Most Valuable Professional on at

    I'm not sure what's your actual problem.

    • You can use SysComputedColumn::comparisonLiteral() to convert an enum element to the right value in SQL.
    • To implement the comparison, you can use SysComputedColumn::equalExpression, or simply construct this piece of code as a string.
    • Use SysComputedColumn::comparisonField() to get references to the fields to compare with.
    • To combine those conditions, use SysComputedColumn::and().

    You can look at reference of these methods to find example in code. For example, look at how StatusIssue is used in InventValueCube::issueAmount():

    return SysComputedColumn::if(
        SysComputedColumn::equalExpression(
            SysComputedColumn::comparisonField(viewName, identifierStr(InventValueTransUnionAll),fieldStr(InventValueTransUnionAll, StatusIssue)),
            SysComputedColumn::comparisonLiteral(StatusIssue::None)),
        SysComputedColumn::returnLiteral(0),
        SysComputedColumn::negative(SysComputedColumn::returnField(viewName, identifierStr(InventValueTransUnionAll),fieldStr(InventValueTransUnionAll, Amount))));

  • ShaqAX Profile Picture
    709 on at

    Thanks,

    Yeap, this is the sample I want to learn or follow. I will take a look first and try, as the actual is the one I described, I want to have COGS value in my data entity which a summary of InventTrans, since CostAmountPosted (Financial cost amount) total is inventory value, right? we cannot see the COGS (my transactions only SO-PO)

    Thanks again.

  • ShaqAX Profile Picture
    709 on at

    How's the "AND" looks like, btw ? Because I need this 2 criteria -> StatusIssue::Sold and InventTransType::Sales

    I'm sorry but this is very confusing for me.

    Thanks

  • Martin Dráb Profile Picture
    237,882 Most Valuable Professional on at

    You can use SysComputedColumn::and() to combine the two conditions.

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 584 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

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

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 254 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans