Chapter 30. Types of columns in guided decision tables
Chapter 30. Types of columns in guided decision tables The Add a new column wizard for guided decision tables provides the following column options. (Select Include advanced options to view all options.) Add a Condition Add a Condition BRL fragment Add a Metadata column Add an Action BRL fragment Add an Attribute column Delete an existing fact Execute a Work Item Set the value of a field Set the value of a field with a Work Item result These column types and the parameters required for each in the Add a new column wizard are described in the sections that follow. IMPORTANT: Required data objects for column parameters Some of the column parameters described in this section, such as Fact Patterns and Fields, provide drop-down options consisting only of data objects already defined within the same package where the guided decision table is found. Available data objects for the package are listed in the Data Objects panel of the Project Explorer and in the Data Objects tab of the guided decision tables designer. You can create additional data objects within the package as needed, or import them from another package in Data Objects New item of the guided decision tables designer. For details about creating data objects, see Section 26.1, "Creating data objects" . 30.1. "Add a Condition" Conditions represent fact patterns defined in the left ("WHEN") portion of a rule. With this column option, you can define one or more condition columns that check for the presence or absence of data objects with certain field values, and that affect the action ("THEN") portion of the rule. You can define a binding for the fact in the condition table, or select one that has previously been defined. You can also choose to negate the pattern. Example rule conditions After a binding is specified, you can define field constraints. If two or more columns are defined using the same fact pattern binding, the field constraints become composite field constraints on the same pattern. If you define multiple bindings for a single model class, each binding becomes a separate model class in the condition ("WHEN") side of the rule. Required column parameters The following parameters are required in the Add a new column wizard to set up this column type: Pattern: Select from the list of fact patterns already used in conditions in your table or create a new fact pattern. A fact pattern is a combination of an available data object in the package (see the note on Required data objects for details) and a model class binding that you specify. (Examples: LoanApplication [application] or IncomeSource [income] where the bracketed portion is the binding to the given fact type) Entry point: Define the entry point for the fact pattern, if applicable. An entry point is a gate or stream through which facts enter the decision engine, if specified. (Examples: Application Stream , Credit Check Stream ) Calculation type: Select one of the following calculation types: Literal value: The value in the cell will be compared with the field using the operator. Formula: The expression in the cell will be evaluated and then compared with the field. Predicate: No field is needed; the expression will be evaluated to true or false . Field: Select a field from the previously specified fact pattern. The field options are defined in the fact file in the Data Objects panel of your project. (Examples: amount or lengthYears fields within the LoanApplication fact type) Binding (optional): Define a binding for the previously selected field, if needed. (Example: For pattern LoanApplication [application] , field amount , and operator equal to , if binding is set to USDamount , the end condition will be application : LoanAppplication(USDamount : amount == [value]) .) Operator: Select the operator to be applied to the fact pattern and field previously specified. Value list (optional): Enter a list of value options, delimited by a comma and space, to limit table input data for the condition ("WHEN") portion of the rule. When this value list is defined, the values will be provided in the table cells for that column as a drop-down list, from which users can select only one option. (Example list: Monday, Wednesday, Friday to specify only these three options) Default value (optional): Select one of the previously defined value options as the default value that will appear in the cell automatically in a new row. If the default value is not specified, the table cell will be blank by default. You can also select a default value from any previously configured data enumerations in the project, listed in the Enumeration Definitions panel of the Project Explorer. (You can create enumerations in Menu Design Projects [select project] Add Asset Enumeration .) Header (description): Add header text for the column. Hide column: Select this to hide the column, or clear this to display the column. 30.1.1. Inserting an any other value in condition column cells For simple condition columns in guided decision tables, you can apply an any other value to table cells within the column if the following parameters are set: Calculation type for the condition column has been set to Literal value . Operator has been set as equality == or inequality != . The any other value enables a rule to be defined for any other field values not explicitly defined in the rules already in the table. In the DRL source, any other is notated as not in . Example rule condition with not in used for any other Procedure Select a cell of a condition column that uses the == or != operator. In the upper-right toolbar of the table designer, click Edit Insert "any other" value . 30.2. "Add a Condition BRL fragment" A Business Rule Language (BRL) fragment is a section of a rule created using the guided rules designer. The condition BRL fragment is the "WHEN" portion of the rule, and the action BRL fragment is the "THEN" portion of the rule. With this column option, you can define a condition BRL fragment to be used in the left ("WHEN") side of a rule. Simpler column types can refer to Facts and Fact fields bound in the BRL fragment and vice-versa. The following example is a condition BRL fragment for a loan application: Figure 30.1. Add a condition BRL fragment with the embedded guided rules designer You can also select Free form DRL from the list of condition options to define the condition BRL fragment without the embedded guided rules designer. Figure 30.2. Add a condition BRL fragment with free form DRL Template keys When you add a field for a condition BRL fragment, one of the value options is Template key (as opposed to Literal or Formula ). Template keys are placeholder variables that are interchanged with a specified value when the guided decision table is generated, and form separate columns in the table for each template key value specified. You can specify the default value of Template key in the Value options page. While Literal and Formula values are static in a decision table, Template key values can be modified as needed. In the embedded guided rules designer, you can add a template key value to a field by selecting the Template key field option and entering the value in the editor in the format USDkey . For example, USDage creates an USDage column in the decision table. In free form DRL, you can add a template key value to facts in the format @{key} . For example, Person( age > @{age} ) creates an USDage column in the decision table. The data type is String for new columns added using template keys. Required column parameters The following parameters are required in the Add a new column wizard to set up this column type: Rule Modeller: Define the condition BRL fragment ("WHEN" portion) for the rule. Header (description): Add header text for the column. Hide column: Select this to hide the column, or clear this to display the column. 30.3. "Add a Metadata column" With this column option, you can define a metadata element as a column in your decision table. Each column represents the normal metadata annotation in DRL rules. By default, the metadata column is hidden. To display the column, click Edit Columns in the guided decision tables designer and clear the Hide column check box. Required column parameter The following parameter is required in the Add a new column wizard to set up this column type: Metadata: Enter the name of the metadata item in Java variable form (that is, it cannot start with a number or contain spaces or special characters). 30.4. "Add an Action BRL fragment" A Business Rule Language (BRL) fragment is a section of a rule created using the guided rules designer. The condition BRL fragment is the "WHEN" portion of the rule, and the action BRL fragment is the "THEN" portion of the rule. With this column option you can define an action BRL fragment to be used in the right ("THEN") side of a rule. Simpler column types can refer to Facts and Fact fields bound in the BRL fragment and vice-versa. The following example is an action BRL fragment for a loan application: Figure 30.3. Add an action BRL fragment with the embedded guided rules designer You can also select Add free form DRL from the list of action options to define the action BRL fragment without the embedded guided rules designer. Figure 30.4. Add an action BRL fragment with free form DRL Template keys When you add a field for an action BRL fragment, one of the value options is Template key (as opposed to Literal or Formula ). Template keys are placeholder variables that are interchanged with a specified value when the guided decision table is generated, and form separate columns in the table for each template key value specified. You can specify the default value of Template key in the Value options page. While Literal and Formula values are static in a decision table, Template key values can be modified as needed. In the embedded guided rules designer, you can add a template key value to a field by selecting the Template key field option and entering the value in the editor in the format USDkey . For example, USDage creates an USDage column in the decision table. In free form DRL, you can add a template key value to facts in the format @{key} . For example, Person( age > @{age} ) creates an USDage column in the decision table. The data type is String for new columns added using template keys. Required column parameters The following parameters are required in the Add a new column wizard to set up this column type: Rule Modeller: Define the action BRL fragment ("THEN" portion) for the rule. Header (description): Add header text for the column. Hide column: Select this to hide the column, or clear this to display the column. 30.5. "Add an Attribute column" With this column option, you can add one or more attribute columns representing any of the DRL rule attributes, such as Saliance, Enabled, Date-Effective, and others. For example, the following guided decision table uses the salience attribute to specify rule priority and the enabled attribute to enable or disable rules for evaluation. Rules with a higher salience value are evaluated first, and rules with the enabled attribute are evaluated only if the check box is selected. Figure 30.5. Example rules with salience and enabled attributes to define evaluation behavior Example rule source with the rule attributes For descriptions of each attribute, select the attribute from the list in the wizard. Hit policies and attributes Note that depending on the hit policy that you have defined for the decision table, some attributes may be disabled because they are internally used by the hit policy. For example, if you have assigned the Resolved Hit policy to this table so that rows (rules) are applied according to a priority order specified in the table, then the Salience attribute would be obsolete. The reason is that the Salience attribute escalates rule priority according to a defined salience value, and that value would be overridden by the Resolved Hit policy in the table. Required Column Parameter The following parameter is required in the Add a new column wizard to set up this column type: Attribute: Select the attribute to be applied to the column. 30.6. "Delete an existing fact" With this column option, you can implement an action to delete a fact that was added previously as a fact pattern in the table. When this column is created, the fact types are provided in the table cells for that column as a drop-down list, from which users can select only one option. Required column parameters The following parameters are required in the Add a new column wizard to set up this column type: Header (description): Add header text for the column. Hide column: Select this to hide the column, or clear this to display the column. 30.7. "Execute a Work Item" With this column option, you can execute a work item handler, based on your predefined work item definitions in Business Central. (You can create work items in Menu Design Projects [select project] Add Asset Work Item definition .) Required column parameters The following parameters are required in the Add a new column wizard to set up this column type: Work Item: Select from the list of your predefined work items. Header (description): Add header text for the column. Hide column: Select this to hide the column, or clear this to display the column. 30.8. "Set the value of a field" With this column option, you can implement an action to set the value of a field on a previously bound fact for the "THEN" portion of the rule. You have the option to notify the decision engine of the modified values which could lead to other rules being reactivated. Required column parameters The following parameters are required in the Add a new column wizard to set up this column type: Pattern: Select from the list of fact patterns already used in conditions or condition BRL fragments in your table or create a new fact pattern. A fact pattern is a combination of an available data object in the package (see the note on Required data objects for details) and a model class binding that you specify. (Examples: LoanApplication [application] or IncomeSource [income] where the bracketed portion is the binding to the given fact type) Field: Select a field from the previously specified fact pattern. The field options are defined in the fact file in the Data Objects panel of your project. (Examples: amount or lengthYears fields within the LoanApplication fact type) Value list (optional): Enter a list of value options, delimited by a comma and space, to limit table input data for the action ("THEN") portion of the rule. When this value list is defined, the values will be provided in the table cells for that column as a drop-down list, from which users can select only one option. (Example list: Accepted, Declined, Pending ) Default value (optional): Select one of the previously defined value options as the default value that will appear in the cell automatically in a new row. If the default value is not specified, the table cell will be blank by default. You can also select a default value from any previously configured data enumerations in the project, listed in the Enumeration Definitions panel of the Project Explorer. (You can create enumerations in Menu Design Projects [select project] Add Asset Enumeration .) Header (description): Add header text for the column. Hide column: Select this to hide the column, or clear this to display the column. Logically insert: This option appears when the selected Fact Pattern is not currently used in another column in the guided decision table (see the field description). Select this to insert the fact pattern logically into the decision engine, or clear this to insert it regularly. The decision engine is responsible for logical decisions on insertions and retractions of facts. After regular or stated insertions, facts have to be retracted explicitly. After logical insertions, facts are automatically retracted when the conditions that asserted the facts in the first place are no longer true. Update engine with changes: This option appears when the selected Fact Pattern is already used in another column in the guided decision table. Select this to update the decision engine with the modified field values, or clear this to not update the decision engine. 30.9. "Set the value of a field with a Work Item result" With this column option, you can implement an action to set the value of a previously defined fact field to the value of a result of a work item handler for the "THEN" portion of the rule. The work item must define a result parameter of the same data type as a field on a bound fact in order for you to set the field to the return parameter. (You can create work items in Menu Design Projects [select project] Add Asset Work Item definition .) An Execute a Work Item column must already be created in the table for this column option to be created. Required column parameters The following parameters are required in the Add a new column wizard to set up this column type: Pattern: Select from the list of fact patterns already used in your table or create a new fact pattern. A fact pattern is a combination of an available data object in the package (see the note on Required data objects for details) and a model class binding that you specify. (Examples: LoanApplication [application] or IncomeSource [income] where the bracketed portion is the binding to the given fact type) Field: Select a field from the previously specified fact pattern. The field options are defined in the fact file in the Data Objects panel of your project. (Examples: amount or lengthYears fields within the LoanApplication fact type) Work Item: Select from the list of your predefined work items. (The work item must define a result parameter of the same data type as a field on a bound fact in order for you to set the field to the return parameter.) Header (description): Add header text for the column. Hide column: Select this to hide the column, or clear this to display the column. Logically insert: This option appears when the selected Fact Pattern is not currently used in another column in the guided decision table (see the field description). Select this to insert the fact pattern logically into the decision engine, or clear this to insert it regularly. The decision engine is responsible for logical decisions on insertions and retractions of facts. After regular or stated insertions, facts have to be retracted explicitly. After logical insertions, facts are automatically retracted when the conditions that asserted the facts in the first place are no longer true. Update engine with changes: This option appears when the selected Fact Pattern is already used in another column in the guided decision table. Select this to update the decision engine with the modified field values, or clear this to not update the decision engine.
when USDi : IncomeSource( type == "Asset" ) // Binds the IncomeSource object to the USDi variable then end when not IncomeSource( type == "Asset" ) // Negates matching pattern then end when IncomeSource( type not in ("Asset", "Job") ) then end rule "Row 1 Pricing loans" salience 100 enabled true when then end rule "Row 3 Pricing loans" enabled false when then end