In this post, I thought that I would try something new, instead of always writing “long” blog posts 😴 about somewhat broad topics. I thought that I would write a small nugget, on a specific topic which in this case are Enums. 😊

Let us start off by looking at what Enums are and why / how we use them. You can view Enums as a replacement for the old option type, and the reason why you should use Enums is quite simple. The reason being that unlike options, then Enums can be extended and they are reusable across objects. The way that Enums work is that you declare a new object of type Enum, in which you create the options that you which to use. The code could look something like the code below.

enum 80200 "Print Actions"
{
    Extensible = true;


    value(0; None)
    {
        Caption = '';
    }
    value(1; "Always Print")
    {
        Caption = 'Always Print';
    }
    value(2; "Confirm")
    {
        Caption = 'Confirm';
  }
}

Now being the good developers that we are 🤓 we should always remember to make our enum object Extensible = true; so that other people can add their own options.

Now using the Enum in our objects is very simple, all you have to do is declare it as a type:

field(5; "Action"; Enum "Print Actions")
        {
            Caption = 'Action';

        }

And that is all there is to it, so now all that is left is to start using it in your Extensions. 😉

Leave a Reply