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, ...
Suggested Answer

How to retrieve enum text instead of integer in entities using computed column(sub query)

(0) ShareShare
ReportReport
Posted on by 1,552

Hi,

So i did this, but in the xml file i;m getting integer value for the enum and not text. How can i show it as text?

public static server str EnumField()
{

    return  strFmt('select top 1 EnumField from Table1 as table1 WHERE table1.PARTITION = %1 AND table1.DATAAREAID = %2 AND table1.Id2 = %3 AND table1.Id1 != %4 AND table1.Id3 = %5'
        , SysComputedColumn::comparisonField(tableStr(Table1View), identifierStr(Table1), fieldStr(Table1, Partition))
        , SysComputedColumn::comparisonField(tableStr(Table1View), identifierStr(Table1), fieldStr(Table1, DataAreaId))
        , SysComputedColumn::comparisonField(tableStr(Table1View), identifierStr(Table1), fieldStr(Table1, Id2))
        , SysComputedColumn::comparisonField(tableStr(Table1View), identifierStr(Table1), fieldStr(Table1, Id1))
        , SysComputedColumn::comparisonField(tableStr(Table1View), identifierStr(Table1), fieldStr(Table1, Id3))
         );

}

I have the same question (0)
  • Suggested answer
    Sergei Minozhenko Profile Picture
    23,093 on at

    Hi JuniorAX,

    You can use a switch statement to convert integer enum value to a string value

    It should be something like below

    private static str EnumField()
    {
    	
    	str formattedValue = "'%1'";
    	Map enumValues = new Map(Types::String, Types::String);
    	
    	enumValue.insert(enum2int(MyEnum::Value1), strFmt(formattedValue, enum2str(MyEnum::Value1)));
    
    	return SysComputedColumn::switch(
    		strFmt('select top 1 EnumField from Table1 as table1 WHERE table1.PARTITION = %1 AND table1.DATAAREAID = %2 AND table1.Id2 = %3 AND table1.Id1 != %4 AND table1.Id3 = %5'
            , SysComputedColumn::comparisonField(tableStr(Table1View), identifierStr(Table1), fieldStr(Table1, Partition))
            , SysComputedColumn::comparisonField(tableStr(Table1View), identifierStr(Table1), fieldStr(Table1, DataAreaId))
            , SysComputedColumn::comparisonField(tableStr(Table1View), identifierStr(Table1), fieldStr(Table1, Id2))
            , SysComputedColumn::comparisonField(tableStr(Table1View), identifierStr(Table1), fieldStr(Table1, Id1))
            , SysComputedColumn::comparisonField(tableStr(Table1View), identifierStr(Table1), fieldStr(Table1, Id3))
             ),
    		enumValues,
    		SysComputedColumn::returnLiteral(''));
    }

  • junior AX Profile Picture
    1,552 on at

    Hi Sergie,

    I didn't understand what do you mean  by this? what should i replace MyEnum::Value1 with?  there are alot of enums that can be returned why did you stick to value1?

    or do you want me to add all values? but this enum has more than 30 values

       enumValue.insert(enum2int(MyEnum::Value1), strFmt(formattedValue, enum2str(MyEnum::Value1)));

    also why the formatted type has " and '?

  • Suggested answer
    nmaenpaa Profile Picture
    101,162 Moderator on at

    Hi junior AX,

    you must put all enum values into the map.

  • Sergei Minozhenko Profile Picture
    23,093 on at

    Hi JuniorAX,

    The idea is that you need to build the map: integer value - string value and you need to add all 30 values. You can use DictEnum class to iterate over all enum values if you don't want to paste 30 insert lines.

    String value should be wrapped with single quotes because it's required by SQL syntax, in SQL view related to your entity you will see a case statement like that:

    CAST(
    	CASE 
    		WHEN 1
    			THEN 'Value2'
    		WHEN 2
    			THEN 'Value2'
    		...
    		ELSE ''
    		END
    	) AS NVARCHAR(20))
    ) AS EnumField

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
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 422 Most Valuable Professional

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 239 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans