Model extensible choices with AL enums

Completed

The work area's classifications must remain meaningful after new apps add choices or an upgrade changes display text. AL enums provide that contract when you treat their integer values as persistent identities rather than display order.

Define stable enum values

An enum declares named values with explicit integers. A table field stores the integer, while the client shows the caption. Set Extensible = true when another extension has a valid reason to add values.

enum 70300 "Work Area Priority"
{
    Extensible = true;

    value(0; Normal) { Caption = 'Normal'; }
    value(10; High) { Caption = 'High'; }
}

The gaps between 0 and 10 don't create a technical requirement, but they leave a readable allocation scheme. Never renumber a published value to change its sort position, and never reuse an old integer for a new meaning. Existing rows retain the integer and would acquire the wrong semantic meaning.

Captions are presentation text. You can localize a caption without changing the value identity. Code should compare enum values, not captions or formatted text.

Assign and convert values deliberately

AL supports direct assignment when both sides use the same enum type:

WorkItem.Priority := "Work Area Priority"::High;

Methods such as AsInteger() expose the underlying integer when an integration contract needs it. Conversion from an integer requires validation because an extension might add values that the current code doesn't explicitly know. Avoid business logic that assumes a fixed number of values or a contiguous sequence.

When you serialize an enum for browser code or an external interface, send a stable machine value and a separate display caption when both are needed. The browser can display the caption, while AL retains responsibility for interpreting the domain value.

Extend without changing the base contract

An enumextension adds values to an extensible enum:

enumextension 70301 "Work Area Priority Ext" extends "Work Area Priority"
{
    value(20; Critical) { Caption = 'Critical'; }
}

The extension allocates its own object ID and globally unique value integers within the enum's effective contract. Downstream code should include a sensible default path when behavior depends on known values. That path keeps the app usable when another extension contributes a value.

Extensibility is a design promise. Mark an enum extensible only when additional values make semantic sense and your validation, filtering, and processing logic can tolerate them.

Migrate options and changed semantics safely

Older tables can use Option fields whose members are identified by ordinal position. An enum improves naming, typing, captioning, and extensibility, but changing a field from Option to an enum still affects stored schema and dependent code.

Use a staged migration for a published field:

  1. Add a new enum field with a new stable field ID.
  2. Map each old option ordinal to the matching enum value in upgrade code.
  3. Update pages, reports, and integrations to use the enum field.
  4. Mark the option field obsolete after consumers move.
  5. Remove it only according to the supported obsoletion policy.

Don't assume that matching captions make an option and enum compatible. Verify the stored ordinal-to-integer mapping and handle blank, unknown, or retired meanings explicitly.

The enum now supplies a stable classification to tables and pages. The final component sends a summarized view of that data to browser code without transferring business authority to the browser.

Learn more at Extensible enums and Enum data type.