Announcements
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.
Hi JuniorAX,
Yes, it should be checked-in also. You can add it manually in the source control explorer in Visual studio.
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?
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.
Hi Sergie,
sorry i meant str2Enum
so str2Enum("Per") why did it consider it as Person?
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
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 ?
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
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?
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
André Arnaud de Cal...
294,118
Super User 2025 Season 1
Martin Dráb
232,866
Most Valuable Professional
nmaenpaa
101,158
Moderator