Dynamics 365 Business Central: Hiding enum values on the page (ValuesAllowed Property)

Dynamics 365 Business Central

Hi, Readers.
Yesterday I saw an interesting question on the Mibuso forum about how to hide enum values on the page.
For details:

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?

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.

Applies to:

  • Table Field
  • Page Field

Syntax: ValuesAllowed = Codeunit, Page, Query;

Remarks:
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.

For example:
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;

Test:
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.

Test Video:

Note:
The property ‘ValuesAllowed’ cannot be customized.

END

Hope this will help.

Thanks for reading.

ZHU

コメント

タイトルとURLをコピーしました