Just found a strange behaviour in using the standard str2enum function. Consider the following code ;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | static void TestOfEnumsWithFirstValueBlank(Args _args) { ProjCategoryType selectedType; str s; ; selectedType = ProjCategoryType::None; s = enum2str(selectedType); // get enum string print s; // shows nothing, since None has no label. selectedType = str2enum(selectedType,s); // convert back if(selectedType == ProjCategoryType::None) print "'None' selected"; else print "undefined..."; // sadly this is printed.. pause; } |
This example code prints undefined, NOT ‘None’ selected. This because str2enum does not handle an empty string in a correct way, even if one of the values in the choosen enum has the emptry string as it’s label. This means values to str2enum must always be validated first before each call..
Last 5 posts in Dynamics AX
- How to call a web API from Dynamics 365 FO X++ - December 1st, 2020
- Cannot add or remove static keyword for this method - May 30th, 2016
- Sales line number not unique - May 27th, 2016
- DMF - DMF Service is unavailable - November 7th, 2012
- DMF - Error occured while doing bulkcopy from temp table to entity table - November 6th, 2012