Επεξεργασία

Κοινή χρήση μέσω


UnknownValueImplementation Property

Version: Available or changed with runtime version 7.0.

Specifies the implementers used for ordinal values that are not included in the defined list of enum values.

Applies to

  • Enum Type

Syntax

UnknownValueImplementation = Interface = InterfaceImplementation;

Example

The following example illustrates different implementations of the IFoo interface. SomeEnum has UnknownValueImplementation set to catch the case where some extension uses an unknown enum value.

pageextension 50130 CustListExt extends "Customer List"
{

    trigger OnOpenPage()
    var
        ifoo: Interface IFoo;
        e: enum SomeEnum;
    begin
        e := SomeEnum::Yes;
        ifoo := e;
        ifoo.Foo(); // => YesFooImpl specified in Implementation on Yes value

        e := SomeEnum::No;
        ifoo := e;
        ifoo.Foo(); // => DefaultFooImpl specified in DefaultImplementation

        e := 2; // No enum value matches this.
        ifoo := e;
        ifoo.Foo(); // => UnknownFooImpl specified in UnknownImplementation
    end;
}

interface IFoo
{
    procedure Foo()
}

codeunit 50145 ErrorFooImpl implements IFoo
{
    procedure Foo()
    begin
        Message('Bad FOO')
    end;
}

codeunit 50146 DefaultFooImpl implements IFoo
{
    procedure Foo()
    begin
        Message('Default FOO')
    end;
}

codeunit 50147 YesFooImpl implements IFoo
{
    procedure Foo()
    begin
        Message('Yes FOO')
    end;
}

enum 50135 SomeEnum implements IFoo
{
    Extensible = true;
    UnknownValueImplementation = IFoo = ErrorFooImpl;
    DefaultImplementation = IFoo = DefaultFooImpl;

    value(0; Yes)
    {
        Implementation = IFoo = YesFooImpl;
    }
    value(1; No)
    {
        // Nothing specified. Using defaults
    }
}

Remarks

The UnknownValueImplementation property applies to enums. Uninstalling enum extensions can result in persisted values becoming unknown. The UnknownValueImplementation provides a generic error handling in such cases. Enums are often used to select an interface implementation. However, due to the nature of an extensible development model, an enum extension and its corresponding interface implementation can be uninstalled from a tenant, while the value for the specific enum is still available, but now pointing to an unknown value. Using the UnknownValueImplementation property when defining an enum prevents throwing a technical error message in the UI and allows for a more user-friendly error handling.

Related to UnknownValueImplementation is the DefaultImplementation property, used for fallback to a default value when no enum value is provided. For more information, see DefaultImplementation Property.

DefaultImplementation Property
Get Started with AL
Developing Extensions