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

Community site session details

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

Get enum label in calculated column

(0) ShareShare
ReportReport
Posted on by

Hello guys,

In regards of calculated column, which the programming a bit different than X++, how to get a label of an Enum inside a calculated Column ?

Thanks

I have the same question (0)
  • Suggested answer
    nmaenpaa Profile Picture
    101,160 Moderator on at
    RE: Get enum label in calculated column

    If I understand correctly, you would like to get a label of an enum value in T-SQL (in a computed column).

    You can read it from SRSAnalysisEnums table.

    By default it contains only English label. But you can use cross references to see where the table is populated, and add your own logic for adding other languages if you need.

  • VoltesDev Profile Picture
    on at
    RE: Get enum label in calculated column

    Hi Nikolaos,

    Noted the table, however the label is not populated and it is on purpose (by Microsoft).

    My options is to populate that or in my data entity, as this is my own custom, is the one should get the label for my specific enum.

    I choose 2nd, but kinda stuck in the code, because it looks like we cannot mix X++ in Calculated column, am I right?

    Any chance of succeed on this attempt?

    Thanks

  • Suggested answer
    nmaenpaa Profile Picture
    101,160 Moderator on at
    RE: Get enum label in calculated column

    Computed columns are not executed by D365 and can't contain x++ code.

    If you want to use a computed column, your solution must work in T-SQL. 

    I think that SRSAnalysisEnums is intended for this exact purpose. And you can populate it with your labels. 

  • Verified answer
    Martin Dráb Profile Picture
    236,394 Most Valuable Professional on at
    RE: Get enum label in calculated column

    You can use SysComputedColumn::switch() to generate T-SQL CASE statement mapping numeric values to label texts. For example:

    public static str computedColumn()
    {
    	SysDictEnum dictEnum = new SysDictEnum(enumNum(MyEnum));
    	Map mapping = SysComputedColumn::comparisionExpressionMap();
    
    	for (int i = 0; i < dictEnum.values(); i  )
    	{
    		mapping.insert(
    			SysComputedColumn::comparisonLiteral(dictEnum.index2Value(i)),
    			SysComputedColumn::returnLiteral(dictEnum.index2Label(i)));
    	}
    
    	str comparisonField = SysComputedColumn::comparisonField(
    		tableStr(MyEntity),
    		dataEntityDataSourceStr(MyEntity, MyTable),
    		fieldStr(MyTable, MyField)));
    
    	return SysComputedColumn::switch(
    		comparisonField,
    		mapping,
    		SysComputedColumn::returnLiteral(''));
    }

  • VoltesDev Profile Picture
    on at
    RE: Get enum label in calculated column

    Hi Martin,

    Much appreciated for your code. It works!

    Thanks.

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

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

#1
CA Neeraj Kumar Profile Picture

CA Neeraj Kumar 2,004

#2
André Arnaud de Calavon Profile Picture

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

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 548 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans