Hiding enum values

twujstarytwujstary Member Posts: 3
Hello,

I am currently working with the newest version of Business Central.

I have created an enum, let's say Enum "Colours" with following values:
• Red,
• Violet,
• Yellow.

Afterwards, I want to create two tables with field "Colour" of type Enum "Colours".

In the first table I want to have all colours available, so the end-user could see: Red, Violet and Yellow as an option.

The second table I would like to have only two of these colours, so the end-user see: Red and Violet.

Is it posible to hide enum values for other fields?

or the only solution is to create two enums - one containing all of the options and the second one, containing only two of these colours?

Best Answer

  • yzhumsyzhums Member Posts: 4
    Accepted Answer
    Try ValuesAllowed property.
    gc4w0hkwxyww.png

    For example:
    mxcjxtmlmda3.png
    s1woprxczqoh.png
    cfcw03iil7zd.png
    clxzt7fqqqw6.png
    7xkgpzlhmxg1.png

Answers

  • yzhumsyzhums Member Posts: 4
    Accepted Answer
    Try ValuesAllowed property.
    gc4w0hkwxyww.png

    For example:
    mxcjxtmlmda3.png
    s1woprxczqoh.png
    cfcw03iil7zd.png
    clxzt7fqqqw6.png
    7xkgpzlhmxg1.png
  • twujstarytwujstary Member Posts: 3
    Hello yzhums,

    thank You for your response. It works as intended.

    But it's a little bit problematic, because let's say that after a while there is a new colour: Orange. So I am typing a new value to Enum Colours. So now I have to remember to go to each table, which uses this enum and add another allowed value, to those fields. Right?

    I didn't find a way to define not allowed values, for specific field, that would be a little bit easier to maintain. Do You know a way to do that?
  • yzhumsyzhums Member Posts: 4
    Yes, as far as I know, this should be the only way. Because ValuesNotAllowed Property does not exist in the BC.
    If you don't hide the value, you can control it in the OnValidate trigger. That might be simpler.

    Since you have to add the value of Enum in VS Code every time, you can maintain this property by the way.
    It may be simpler to refer to the following method.

    nfo8jcajb0fs.png
    vs6oa6rft15o.png



  • twujstarytwujstary Member Posts: 3
    Yes, I know about references, but I will rather go with creating new Enum instead, I guess.

    Imagine using this particular enum for 500 different fields In that case you would have to analyze each field individually - either you want new value or not.

    In my opinion it's easier to have few enums - maybe it's uglier solution, but I have to think in a little bit bigger perspective.

    Thank you for your time though. :smile:
Sign In or Register to comment.