Get Integer from Enum in BC 13 and BC 14

This is just one of my own feature reminders. Since I develop extensions for customers in older Business Central versions (e.g. October 2018 release and April 2019 release) I often run into the problem that many enum functions like AsInteger() are only available in runtime versions > 4.0.

image 26
So to get the integer value of an enum field, you have to trick a bit:
enum 50100 "My Order State"
{
    value(0; None)
    {
    }
    value(1; Imported)
    {
    }
    value(2; Accepted)
    {
    }
    value(3; Shipping)
    {
    }
}
 local procedure GetIntegerFromEnum(OrderState: enum "My Order State") r: Integer
 begin
     Evaluate(r, format(OrderState, 0, 9));
 end;

... is a technical consultant and developer at Comsol Unternehmenslösungen AG in Kronberg/Taunus. Major tasks are the architecture and implementation of complex, usually cross-system applications in and around Microsoft Dynamics 365 Business Central.

Leave a Reply

Your email address will not be published.