To define a variable of type Option, you can’t use the OptionMembers property that’s used on a field of data type Option. You need to list the available options as a comma-separated list after your variable definition.
For example:- Color: Option Red,Green,Yellow;
If you want to reuse the same Option type in other objects (like other codeunits, pages, or tables), you have to redefine all available values. Later, if you decide to add an extra value, you need to modify all objects with this extra value. Options in a table are not extendable with a table extension.
Solution to this is now available as enum.
An enum is a separate object with its own number and name. You can use an Enum object in other object without the need to redefine it at each object level. The Enum object can also be extended with enum extensions.
Lets see example defining and using enum.

I have created a EnumDefinition.al to define my custom enum Color.

I have defined one Function SelectColor to access values.

To call the Function and test result created extension of Customer List page and added code to access the value.
Now we can use this Enum throughout the extension in any objects without redefining it as in case of Option.
Let’s Publish the extension and see the result.

As you can remember from above code, I have selected color Green and have put the code to call of function on trigger of Customer List page, OnOpenPage.
The Enum object can also be extended with enum extensions.
Extending the Enum
Lets create new Extension, app.json file set dependencies to earlier/above Extension.

Next let’s extend our enum Color.

Next let’s create codeunit for function to access value of enum.

To call the Function and test result created extension of Customer List page and added code to access the value.

Let’s Publish the extension and see the result.

As you can remember from above code, I have selected color Red & Brown and have put the code to call of function on trigger of Customer List page, OnOpenPage.
Red is from earlier defined Color enum (Red, Green, Yellow), & Brown from extended enum (Blue, Black, Brown).
1 thought on “Options VS Enums”
Comments are closed.