6.7. Data Enumerations
6.7.1. Data Enumerations Drop-Down List Configuration
Data enumerations are an optional type of asset that can be configured to provide drop-down lists for the Guided Decision Table Editor. Double-click on a cell to view the enumeration drop-down list if the cell condition is based the same fact and field as the enumeration.
They are stored and edited just like any other asset and only apply to the package they are created in.
The contents of an enumeration configuration are the mapping of a
fact.field to a list of values. These values are used to populate the drop-down menu. The list can either be literal or use a utility class (which must be added to the classpath) to load the strings. The strings contain either a value to be shown in the drop-down menu or a mapping from the code value (which is what is used in the rule) and a display value, e.g., M=Mini.
Example 6.2. An Example Enumeration Configuration
'Board.type' : [ 'Short', 'Long', 'M=Mini', 'Boogie'] 'Person.age' : [ '20', '25', '30', '35' ]
This can be also be configured in Business Central as follows:
6.7.2. Advanced Enumeration Concepts
Drop-down lists are dependent on field values. With enumerations it is possible to define multiple options based on other field values.
A fact model for insurance policies could have a class called Insurance, consisting of the fields,
coverage. The choices for
policyType could be
Car. The type of insurance policy will determine the type of coverage that will be available. A home insurance policy could include
liability. A car insurance policy could include
The field value policyType determines which options will be presented for coverage, and it is expressed as follows:
'Insurance.policyType' : ['Home', 'Car'] 'Insurance.coverage[policyType=Home]' : ['property', 'liability'] 'Insurance.coverage[policyType=Car]' : ['collision', 'fullCoverage']
6.7.3. Obtaining Data Lists from External Sources
A list of Strings from an external source can be retrieved and used in an enumeration menu. This is achieved by adding code to the classpath that returns a
java.util.List (of strings). Instead of specifying a list of values in the user interface, the code can return the list of strings. (As normal, you can use the "=" sign inside the strings if you want to use a different display value to the rule value.) For example, you could use the following:
'Person.age' : ['20','25', '30', '35']
'Person.age' : (new com.yourco.DataHelper()).getListOfAges()
This assumes you have a class called
DataHelper which has a method
getListOfAges() which returns a list of strings. The data enumerations are loaded the first time the guided editor is used in a session. To check the enumeration has loaded, go to the package configuration screen. You can "save and validate" the package; this will check it and provide feedback about any errors.