When you’re first learning X++, it helps to get comfortable with how enums can be turned into readable strings. The function most beginners run into is enum2str. This takes an enum value, like WHSWorkStatus::InProgress, and gives you back the name of that value as a string, for example "InProgress". This is useful when you want to log what the system is doing, or show a simple text message without worrying about localization.
Imagine you’re working in an electronics warehouse and need to keep track of put-away work for a shipment of televisions. You might pull a work record and check its status. Using enum2str, you can log that status in a way that is readable both for you and for other developers supporting the system:
// Log the status of warehouse work during a TV restock
WHSWorkTable work = WHSWorkTable::find("WORK-04567");
info(strFmt("Work %1 is currently %2",
work.WorkId,
enum2str(work.Status))); // Prints "InProgress"
This makes debugging easier because you don’t just see a number (like 2), you see the actual name of the enum element. For user-facing forms and reports, you might instead create a display method on the table. A display method is a calculated field that shows up like a column, without being physically stored in the database. Here’s a simple example that always returns the status text for a record:
public display str WorkStatusText()
{
return enum2str(this.Status);
}
Now whenever a warehouse clerk looks at a grid of work records, they can see a clean text value for status without needing to understand internal codes.
As you move from beginner to intermediate, you’ll also see places where you need to explore all values of an enum. That’s where classes like SysDictEnum come in. These let you loop through the metadata of an enum and fetch values, names, and labels. For example, index2Name gives you the technical name, while index2Label gives you the user-facing label. This becomes important when you want to build a dropdown in a dialog that lists all possible statuses a work record might have.
It’s worth keeping in mind that enum2str gives you the element name, not the localized text that end users see in their language. For that, you’d use enum2Label instead. And if you’re working with storage or integrations, sometimes you’ll need to go the other direction, converting from a string back to an enum value with str2Enum, or converting an integer back with any2Enum.
So the general path for a warehouse developer is this: use enum2str when you want something technical but readable, use enum2Label when you’re showing something to end users, and explore SysDictEnum if you need to work with the full list of values programmatically. Later on, you’ll also find enum2int and the reverse functions just as handy when dealing with stored values, configuration tables, or integrations. Together, these tools make enums flexible and easy to work with in the day-to-day world of electronic retail warehousing.
Have a Question ?
Fill out this short form, one of our Experts will contact you soon.
Talk to an Expert Today
Call Now