Yesterday I saw an interesting question on the Mibuso forum about how to hide enum values on the page.
I am currently working with the newest version of Business Central.
I have created an enum, let’s say Enum “Colours” with following values:
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?Hiding enum values — mibuso.com
Yes, it is possible. This time we need to use ValuesAllowed Property.
ValuesAllowed Property: Sets the values that are allowed in the field.
- Table Field
- Page Field
Syntax: ValuesAllowed = Codeunit, Page, Query;
Separate the values with a comma. For example, if you only want the user to enter 1, 3, or 5 in this field, enter 1,3,5 for this property.
The property setting is checked during validation. Validation occurs only if the field or control value is updated through the UI, for example, if a value is updated on a page or if a field is updated in a table. If a field is updated through application code, then the ValuesAllowed property is not validated.
1. Create a new Colours enum object.
2. Add a new field with the field “Colour” of type Enum “Colours” and then display it on the page.
In sales line table.
In Purchase Line table.
3. Add ValuesAllowed property to set the values that are allowed in the field.
For example: ValuesAllowed = 0, 1, 3;
On the Sales Order Subform page: You can see all enum values.
On the Purchase Order Subform page: You can only see the enum values set on the ValuesAllowed property.
The property ‘ValuesAllowed’ cannot be customized.
Hope this will help.
Thanks for reading.