Enum Data Type

by Dec 27, 2019AL Language

Home 9 Development 9 AL Language 9 Enum Data Type

Enum is a new data type in the Business Central introduced with the very first version of Business Central. Since then many changes have been done to them and currently, they are usable instead of Option data type without any hesitation.

In compare to Option, Enums have more benefits and moreover, they can be shared across more fields without the need to specify them again and again for every field.

The main advantages are

  • Single specification of options across multiple fields.
  • Extensible (if allowed)
  • Better readability if more values are defined

Example

Enum looks like any other object in AL (see below). In the property section of the object, there is only one interesting property – Extensible. By default, the value is true; however, if we don’t want the enum extensible from another extension, we can change the value to false.

In the body part, we define values. For each value, we can define ID, Name and Caption. The major difference from Option Data Type is how we define ID. In option, we had to put as many commas as we needed to get the ID, in Enums, we just write the ID as a number.

 enum 50100 "TKA Example Enum"
 {
    Extensible = true;
    
    value(0; " ")
    {
        Caption = ' ';
    }
    value(1; "TKA First Option")
    {
        Caption = 'First Option';
    }
    value(10; "TKA Second Option")
    {
        Caption = 'Second Option';
    }
 }

Usage

Usage of Enum is very similar to Record/Page/… variables. See the difference from Option declaration.

 table 50100 "TKA Example Table"
 {
    ...
    fields
    {
        ...
        field(100; "TKA Option Field"; Option)
        {
            OptionMembers = " ","TKA First Option",,,,,,,,,"TKA Second Option";
            OptionCaption = ' ,First Option,,,,,,,,,Second Option';
        }
        field(101; "TKA Enum Field"; Enum "TKA Example Enum")
        {
        }
        ...
    }
    ...
 } 

Recent Articles from the category

BC Open Source? How to start?

BC Open Source? How to start?

BC Open Source? How to start? One of the most exciting news introduced last month in Lyon during Directions EMEA 2023 was the changes to the open-source initiative. This means that you can now contribute to the source code of the Base app and the System app, which are...

read more
Validate a FlowField Field. Wait? What?

Validate a FlowField Field. Wait? What?

Validate a FlowField Field. Wait? What? There are not many things in the AL Language that surprised me. However, last week, I found one such thing - I reviewed customizations made by another partner and had to analyze the OOTB code of the Demand Forecast matrix. I run...

read more
Dynamics NAV 2013 & Expired Cronus License

Dynamics NAV 2013 & Expired Cronus License

We found an interesting problem - we were not able to run the development environment for Dynamics NAV 2013. Whenever we tried to run the development client, we got the following error message: "Your program license has expired" and the development client has closed...

read more
Indirect Dependencies and Access Modifiers

Indirect Dependencies and Access Modifiers

Last week, there was a discussion on Yammer on how to get values from the "Sent Email" record when all fields are marked as Internal. I was surprised that many people do not know what can/can't access modifiers (such as local, protected, or internal) be used for. I...

read more
AL Extensions: Replace Document Attachment

AL Extensions: Replace Document Attachment

I have published a new simple, open-source extension that allows replacing existing document attachments in all master entities as well as in open documents. The source code as well as the app file that can be installed in your environment is available on my GitHub...

read more

Sign Up for News

Certifications

Highest certification
Microsoft Data Management and
also in D365 Business Central

Microsoft Certified: Dynamics 365 Business Central Functional Consultant Associate

See other certifications here