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

Need help on computed column for enum label

(0) ShareShare
ReportReport
Posted on by 901

Hi guys,

I have data entity that currently need to add one field for my enum value, which is the enum label;. Need your help to verify or allocate what is wrong with my syntax, as currently it looks like my enum with value 0 is having empty string.

Here is the code :

public static server str TypeName()
    {
        TableName       viewName  = tableStr(MyDeviceDIM);
        SysDictEnum     dictEnum = new SysDictEnum(enumNum(DeviceType));
        int enumIdx;
        Map valuesMap = SysComputedColumn::comparisionExpressionMap();
     
        for (enumIdx = 0; enumIdx <= dictEnum.values(); enumIdx  )
        {
            valuesMap.insert(
            SysComputedColumn::comparisonLiteral(dictEnum.index2Value(enumIdx)),
            SysComputedColumn::returnLiteral(dictEnum.index2Label(enumIdx)));
        }
    
        str comparisonField = SysComputedColumn::comparisonField(
        viewName,
        dataEntityDataSourceStr(MyDeviceDIM, MyDeviceTable),
        fieldStr(MyDeviceTable, DeviceType));

        return SysComputedColumn::switch(
            comparisonField,
            valuesMap,
            SysComputedColumn::returnLiteral(''));
    }

Some information:

MyDeviceDIM is my data entity name, inside the data source is the table name MyDeviceTable and the enum field in that table is DeviceType which having the same name as its enum name.

I only have 2 component in my enum, with value 0 and 1, lets say the label is "label1" and "label2", so currently only those field with value 1 return this new computed column a value of "label2", the other (0) is just an empty string.

Anyone can help me what is wrong with those code ?

Thanks in advance.

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

    You you please show us T-SQL code generated by your X++ code? It should be easier to spot the problem there.

  • Tony zhong Profile Picture
    901 on at

    Hi Martin,

    Yeah this is it, found the wrong in SQL, although don't know why it became like that :D

    ( Cast (( CASE T1.devicetype
                       WHEN 0 THEN ''
                       WHEN 1 THEN N'Label2'
                       ELSE ''
                     END ) AS NVARCHAR(20)) )
           AS TYPENAME

    Not sure why "when 0 then ''

    But I can assure you, both enum component has its label defined already.

    Thanks

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

    Then you can debug your X++ code to see why it generates such T-SQL code.

    It seems that dictEnum.index2Label(0) returns an empty string. Isn't it the case? Are you sure that you've set the Label property of the first enum element?

  • Tony zhong Profile Picture
    901 on at

    Means to say nothing wrong in the code, is it ?

    Yes, the label is set, and we have use this enum for long time ago actually, works well in all the form in F&O, it is only now I need to add the label in my data entity.

    Thanks,

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

    Please debug the code to see where if fails.

    As I said, the generated code suggests that dictEnum.index2Label(0) returns an empty string. Please test this hypothesis.

  • Tony zhong Profile Picture
    901 on at

    Hmm, ok, but how to debug data entity, then ?

    Since it didn't use in any of the forms or some buttons, it is just a data entity which is for external usage.

    Thanks,

  • YY Lim Profile Picture
    960 on at

    Do you have multiple language file and the language file is with the correct label such as for example both en-us and en-gb has the same label?

  • Tony zhong Profile Picture
    901 on at

    Hi,

    Yes, we did have multiple language, but how to know which one is used in that data entity ?

    The label set in that enum component is to language EN-US, both of them.

    Thanks

  • YY Lim Profile Picture
    960 on at

    Can you check your user account language that executing the code, or what you can do is set the other label file to the same label to test it whether is because of language issue.

  • Tony zhong Profile Picture
    901 on at

    Hi,

    If "user account language" by means those in User options > Preferences, it did set as "en-us" as well. At first I thought it is language issue, but to think again, is it true ? 'cause even in SQL backend when I check is resulting that 'wrong' SQL query.

    In the backend, if we check via SSMS, shouldn't "attached" to any setup inside F&O, can I say that ? I'm sorry but I never work with multiple language before but this my understanding.

    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…

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

#2
André Arnaud de Calavon Profile Picture

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

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 278 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans