D365 Business Central : Hide Enum Values
Enum is great way to centralized your list of options in Business Central. You can define an enum, then use the enum on every objects (such as table, page, report, etc) and they will all have the same list of options.
However, what if you want to hide some of the options on specific pages or tables because it is not valid option for them ? It’s a good design to only provide user with only the options that they are allowed to choose.
Let’s take a look at one of the standard enum: Enum 37 “Sales Line Type”.
You have 6 options to choose from : ” “, “G/L Account”, “Item” , “Resource”, “Fixed Asset”, and “Charge (Item)”.
What if you only want user to select Item and Resource only ? You can use ValuesAllowed property to limit the option.
Let’s create a test page with two fields: one without ValuesAllowed property, one with the ValuesAllowed property set to Item and Resource.
page 50000 "Test Enum Page"
{
Caption = 'Test Enum';
PageType = Card;
layout
{
area(content)
{
field(WithoutValuesAllowed; SalesLineType)
{
ApplicationArea = All;
Caption = 'Without ValuesAllowed';
}
field(WithValuesAllowed; SalesLineType)
{
ApplicationArea = All;
Caption = 'With ValuesAllowed';
ValuesAllowed = "Item", "Resource";
}
}
}
var
SalesLineType: Enum "Sales Line Type";
}
As you can see from the result, the second field with ValuesAllowed property only shows two options: Item and Resource.
However, this method can only provide a static predefined list. What if you want to do it dynamically based on parameters ? One way of doing it is to use a temporary table. You can populate that temporary table based on your parameters and use that table to provide user with the related choices.
Hope that helps.