Reserve Enum value zero (0) for empty value

Properties
AC0019 Info Design Code Fix Ignore Obsolete

When defining an enum, it is natural to assign meaningful names starting at ordinal 0. If ordinal 0 carries a meaningful business value, new records silently start with that value — making it impossible to distinguish an intentional selection from a platform default.

By reserving the zero value for an empty sentinel upfront, adding an empty option later — a common request — is trivial: ordinal 0 is already in place.

Zero vs Null

Business Central stores enums as integers. The platform does not support nullable values — a new record is automatically assigned 0 for every enum field. When a table extension adds a new enum field, all existing records also receive 0. There is no way to tell whether a user deliberately selected the value at ordinal 0 or the platform assigned it as a default.

Reserve ordinal 0 for an empty sentinel and start meaningful values at 1 or higher.

Example

The following enum assigns a meaningful name and caption to ordinal 0:

enum 50100 MyEnum
{
    value(0; MyValue) // Reserve Enum value zero (0) for empty value [AC0019]
    {
        Caption = 'My Value';
    }
}

Reserve 0 as the empty value and shift meaningful values to 1:

enum 50100 MyEnum
{
    value(0; " ")
    {
        Caption = '';
    }
    value(1; MyValue)
    {
        Caption = 'My Value';
    }
}

Alternatively, omit ordinal 0 entirely:

enum 50100 MyEnum
{
    value(1; MyValue)
    {
        Caption = 'My Value';
    }
}

Both approaches keep ordinal 0 free of business meaning. Declaring an explicit empty value (" ") makes the blank option visible and selectable in dropdowns; omitting 0 hides it but the field still defaults to 0 at runtime.

The name matters for selection behavior: " " (a single space) creates a value the user can pick from the dropdown, while an empty name hides the value from the list — the user cannot select it, but the field still defaults to 0 on new records.

When the diagnostic is reported

  • The enum value at ordinal 0 has a non-whitespace name.
  • The enum value at ordinal 0 has a whitespace name but a non-whitespace caption.

Exception

Enums that implement an interface are excluded. Interface implementations require each value to map to a concrete implementation codeunit, so reserving ordinal 0 as a blank sentinel is impractical.

enum 50100 "Code Analyzer" implements IAnalyzer
{
    value(0; LinterCop)
    {
        Caption = 'LinterCop';
        Implementation = IAnalyzer = LinterCopAnalyzer;
    }
    value(1; CompanialCop)
    {
        Caption = 'CompanialCop';
        Implementation = IAnalyzer = CompanialCopAnalyzer;
    }
}

When the rule must be suppressed for other reasons, use a pragma directive:

#pragma warning disable AC0019
enum 50100 MyEnum
{
    value(0; Quote)
    {
        Caption = 'Quote';
    }
}

See also