Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested answer

Warning Assigning a numerical value to extensible enum 'Extensible Enumeration(DirPartyType)' will yield unexpected results. Extensible enum values are not deterministically assigned to a numerical value

(0) ShareShare
ReportReport
Posted on by 1,552

Hi,

I'm passing a dirPartyType from a service as a string. but the problem with using str2Enum was that if i passed "Person" or "Per" then it will consider it as Person. But i should get invalid dirPartyType if i passed "Per"

DirPartyType dirPartyType;
Test::create(str2Enum(dirPartyType,_req.DirPartyType())  // where req.DirPartyType() is filled from .Net a string

public static Test create(DirPartyType _dirPartyType)
{
    if(_dirPartyType == DirPartyType::Person)
    {
        return new TestPCreator();
    }
    else if(_dirPartyType == DirPartyType::Organization)
    {
        return new TestOCreator();
    }
    else
    {
        throw error('Invalid DirPartyType');
    }
}

So it was suggested that i should use DictEnum and indeed it solved my problem and detected "Per" as invalid

DictEnum dictEnum = new DictEnum(enumNum(DirPartyType));
Test::Creater(dictEnum.symbol2Value(_req.DirPartyType()));

1. However using this DictEnum resulted in getting the warning i mentioned in the question. How to solve this?

2. what's the difference between BP warning and warnings alone. As this warning is not a BP.

  • Sergei Minozhenko Profile Picture
    23,091 on at
    RE: Warning Assigning a numerical value to extensible enum 'Extensible Enumeration(DirPartyType)' will yield unexpected results. Extensible enum values are not deterministically assigned to a numerical value

    Hi JuniorAX,

    Yes, it should be checked-in also. You can add it manually in the source control explorer in Visual studio.

  • junior AX Profile Picture
    1,552 on at
    RE: Warning Assigning a numerical value to extensible enum 'Extensible Enumeration(DirPartyType)' will yield unexpected results. Extensible enum values are not deterministically assigned to a numerical value

    Hi Sergie,

    yeah maybe it's a bug.

    but I added the xml files in AXIgnoreList but i can't find them in pending changes, should these be checked in?

  • Sergei Minozhenko Profile Picture
    23,091 on at
    RE: Warning Assigning a numerical value to extensible enum 'Extensible Enumeration(DirPartyType)' will yield unexpected results. Extensible enum values are not deterministically assigned to a numerical value

    Hi JuniorAX,

    To be honest I have not idea if it's a bug or correct behavior (looks like a bug). But usually, you don't need to use str2Enum as it converts from label to enum value, and the label is something that can be easily changed, but instead, Symbol2Value should be used as it uses enum element name instead of a label.

  • junior AX Profile Picture
    1,552 on at
    RE: Warning Assigning a numerical value to extensible enum 'Extensible Enumeration(DirPartyType)' will yield unexpected results. Extensible enum values are not deterministically assigned to a numerical value

    Hi Sergie,

    sorry i meant str2Enum

    so str2Enum("Per")  why did it consider it as Person?

  • Suggested answer
    Sergei Minozhenko Profile Picture
    23,091 on at
    RE: Warning Assigning a numerical value to extensible enum 'Extensible Enumeration(DirPartyType)' will yield unexpected results. Extensible enum values are not deterministically assigned to a numerical value

    Hi JuniorAX,

    I think it was already described in another topic community.dynamics.com/.../enum2str-not-working-correctly

    enum2str - translates enum value to localized label value

    For example

    enum2str(SalesStatus::Backorder) returns "Open order" for users who are using en-us language

    Symbol2Value - translate string representation for enum element name to enum value

    DictEnum.Symbol2Value("Backorder") return interger value for SalesStatus::Backorder value

  • junior AX Profile Picture
    1,552 on at
    RE: Warning Assigning a numerical value to extensible enum 'Extensible Enumeration(DirPartyType)' will yield unexpected results. Extensible enum values are not deterministically assigned to a numerical value

    Hi Sergie,

    I mean when i was using enum2Str it wasn't detecting the string i pass correctly.

    As i described if i pass "Person" or "Per" it will detect it as a valid dirPartyType which is Person

    However when i used dictEnum.symbol2Value("Per") it detect it as an invalid one

    so what's the difference between using enum2str and  dictEnum.symbol2Value? why enum2str didn't detect it? and what does symbol2Value do?

    Also is the dictEnum the only way to solve the issue, could there be another way to solve it ?

  • Suggested answer
    Sergei Minozhenko Profile Picture
    23,091 on at
    RE: Warning Assigning a numerical value to extensible enum 'Extensible Enumeration(DirPartyType)' will yield unexpected results. Extensible enum values are not deterministically assigned to a numerical value

    Hi JuniorAX,

    1 and 2. Not sure what you mean. Symbol2Value and enum2str completely different functions and have different purposes.

    3. Yes, you can suppress it

      Compile
      Warning
      dynamics://Class/MyClass/Method/myMethod 
      CastFromExtensibleEnum
      enum2Symbol case
    

  • junior AX Profile Picture
    1,552 on at
    RE: Warning Assigning a numerical value to extensible enum 'Extensible Enumeration(DirPartyType)' will yield unexpected results. Extensible enum values are not deterministically assigned to a numerical value

    Hi Sergie,

    1. is DicEnum the only was to solve my issue?

    2. what is the difference between using dicEnum symbol2Value and enum2str, why str2Enum doesn't work?

    3. can i suppress this warning? as it's not a BP?

  • Suggested answer
    Sergei Minozhenko Profile Picture
    23,091 on at
    RE: Warning Assigning a numerical value to extensible enum 'Extensible Enumeration(DirPartyType)' will yield unexpected results. Extensible enum values are not deterministically assigned to a numerical value

    Hi JuniorAX,

    1. I think you can just ignore it as you don't compare the enum value with a static integer value and your code will work always correctly.

    2. It's compile warning

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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Jonas ”Jones” Melgaard – Community Spotlight

We are honored to recognize Jonas "Jones" Melgaard as our April 2025…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 294,118 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 232,866 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Product updates

Dynamics 365 release plans