
Convert string into enum str2enum in x++
This post will explain how you can assign and convert string input either read from excel etc into enum type variable. For this example, we’ll be going to use SalesStatus Enum used in Sales order to define its current state. Enum has 2 key properties
- Name – enum element name
- Label – it is used as a string for enum conversion

Public static anytype str2enum(anytype type, str text)
SalesStatus salesStatus; | |
str salesStatusValue = 'Open order';//note blank value can also be used | |
//if enum have None element otherwise value is mandatory | |
salesStatus = str2Enum(salesStatus,salesStatusValue); | |
Info(enum2Str(salesStatus)); | |
// this will info 'Open order' | |
Info(enum2Str(SalesStatus::Backorder)); | |
//this will also info 'Open order' |
I hope this article helped you learn how to use str2enum (x++) in the D365 Finance & operations AX. Don’t forget to share this article.
You may also want to see our article on How to handle 401 unauthorised error in x++. You can find us on facebook.
No Comments