6.4. Web Based Guided Decision Tables

6.4.1. Web Based Guided Decision Tables

The (web based) Guided Decision Table feature works similar to the Guided Editor by introspecting what facts and fields are available to guide the creation of a decision table.
Rule attributes, meta-data, conditions and actions can be defined in a tabular format thus facilitating rapid entry of large sets of related rules. Web based decision table rules are compiled into DRL like all other rule assets.
To create a new decision table, click on New ItemGuided Decision Table. Enter the name of the table and select whether you want the extended entry or limited entry table (Section 6.4.2, “Types of decision tables”). Optionally select to use the Guided Decision Table Wizard.
Click OK when done. If you didn't select the wizard, you will be presented with the editor for Guided Decision Tables. If you selected the wizard, you will be presented with the first screen of the wizard.
The wizard helps you define your imports, facts, patterns and columns, but not the rows. Rows are added in the Guided Decision Table Editor, which is what you are presented with at the end of the wizard (or directly if you didn't use the wizard).
A brand new empty decision table

6.4.2. Types of decision tables

There are broadly two types of decision tables, both of which are supported:
  • Extended Entry
  • Limited Entry
Extended entry

An Extended Entry decision table is one for which the column definitions specify Pattern, Field and operator but not value. The values, or states, are themselves held in the body of the decision table. It is normal, but not essential, for the range of possible values to be restricted by limiting entry to values from a list. Business central supports use of Java enumerations or decision table "optional value lists" to restrict value entry.

Limited entry

A Limited Entry decision table is one for which the column definitions specify value in addition to Pattern, Field and operator. The decision table states, held in the body of the table, are boolean where a positive value (a checked tick-box) has the effect of meaning the column should apply, or be matched. A negative value (a cleared tick-box) means the column does not apply.

6.4.3. Column Configuration

Columns can have the following types of constraint:
  • Literal
    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.
You can set a default value, but normally if there is no value in the cell, that constraint will not apply.
Within the Options section under the Decision table, the user has the ability to set a default value.

Figure 6.6. Column Configuration

6.4.4. Adding Columns

To add a column within the Guided Decision Table Editor, click on the New Column icon.
The following column type selection dialog appears:
Add column pop-up for Guided Decision Tables in BRMS User Guide 6.0.2

Figure 6.7. Advanced Column Options

By default, the column type dialog shows the following types:
  • Add a new Metadata\Attribute column
  • Add a simple Condition
  • Set the value of a field
  • Set the value of a field on a new fact
  • Delete an existing fact
Clicking on "Include advanced options" adds the following options:
  • Add a Condition BRL fragment
  • Execute a Work Item
  • Set the value of a field with a Work Item parameter
  • Set the value of a field on a new Fact with a Work Item parameter
  • Add an Action BRL fragment

6.4.5. Column Types

6.4.5.1. Attribute Columns

Zero or more attribute columns representing any of the DRL rule attributes can be added. An additional pseudo attribute is provided in the guided decision table editor to "negate" a rule. Use of this attribute allows complete rules to be negated. For example, the following simple rule can be negated as also shown.
when
  $c : Cheese( name == "Cheddar" )
then
  ...
end
when
  not Cheese( name == "Cheddar" )
then
  ...
end

6.4.5.2. Metadata Columns

Zero or more meta-data columns can be defined, each represents the normal meta-data annotation on DRL rules.
Attribute and Meta Data option for the Guided Decision Table in the BRMS User Guide 6.0.2

Figure 6.8. Attribute and MetaData Option

6.4.5.3. Condition Columns

Conditions represent fact patterns defined in the right-hand side, or "when" portion, of a rule. To define a condition column, you must define a binding to a model class or select one that has previously been defined. You can choose to negate the pattern. Once this has been completed, 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 right-hand side of the rule.
When you edit or create a new column, you will be given a choice of the type of constraint:
  • Literal : 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.
Condition Column for Guided Decision Table Editor in the BRMS User Guide 6.0.2

Figure 6.9. Simple Condition Column

6.4.5.4. Field Value Columns

Creates an Action to set the value of a field on a previously bound fact. You have the option to notify the Rule Engine of the modified values which could lead to other rules being re-activated.
Field Value column for the Guided Decision Table Editor in BRMS User Guide 6.0.2

Figure 6.10. Set the value of a field

6.4.5.5. New Fact Field Value Columns

This column allows an Action to insert a new Fact into the Rule Engine Working Memory, and it sets the value of one of the new Facts' fields. You can choose to have the new Fact "logically inserted;" that is, it will automatically be deleted should the conditions leading to the action being invoked cease to be true. Please refer to the Red Hat JBoss Development Guide for information about truth maintenance and logical insertions.
New Fact Field value column for the Guided Decision Table Editor in BRMS User Guide 6.0.2

Figure 6.11. Set the value of a field on a new fact

6.4.5.6. Delete Existing Fact Columns

The implementation of an Action to delete a bound Fact.
Delete Existing Fact column for the Guided Decision Table Editor in BRMS User Guide 6.0.2

Figure 6.12. Delete an existing fact

6.4.6. Advanced Column Types

6.4.6.1. Condition BRL Fragment Columns

A construct that allows a BRL fragment to be used in the left-hand side of a rule. A BRL fragment is authored using the Guided Rule Editor and hence all features available in that editor can be used to define a decision table column such as the following: "from", "collect", and "accumulate". When using the embedded Guided Rule Editor, field values defined as "Template Keys" will form columns in the decision table. Facts and Fact's fields bound in the BRL fragment can be referenced by the simpler column types and vice-versa.
The following example displays a BRL Condition for a shopping tier.
Condition BRL Fragment column for Guided Decision Table Editor in BRMS User Guide 6.0.2

Figure 6.13. Add a Condition BRL fragment

6.4.6.2. Execute Work Item Columns

This implements an Action to invoke a Red Hat JBoss Business Process Management Suite Work Item Handler. It sets its input parameters to bound Facts/Facts' fields values. This works for any Work Item Definition.
Execute Work Item Columns for Guided Decision Table Editor in BRMS User Guide 6.0.2

Figure 6.14. Execute a Work Item

WS Work Item Name for the Guided Decision Table in BRMS User Guide 6.0.2

Figure 6.15. WS Work Item

REST Work Item for Guided Decision Table Editor in BRMS User Guide 6.0.2

Figure 6.16. REST Work Item

Log Work Item for Guided Decision Table Editor in BRMS User Guide 6.0.2

Figure 6.17. Log Work Item

Email Work Item for Guided Decision Table Editor in BRMS User Guide 6.0.2

Figure 6.18. Email Work Item

6.4.6.3. Field Value with Work Item Parameter Columns

This implements an Action to set the value of a Fact's field to that of a Red Hat JBoss Business Process Management Suite Work Item Handler's result parameter. The Work Item needs to define a result parameter of the same data-type as a field on a bound fact; this will allow you to set the field to the return parameter.
Field Value with Work Item Parameter in Guided Decision Table Editor in BRMS User Guide 6.0.2

Figure 6.19. Set the value of a field with a Work Item parameter

Note

Please note that in order to set the "Bind field to Work Item" option, you first need to have an Action executing a Work Item. This will allow you to set the field of an existing Fact based on a Work Item's results.

6.4.6.4. New Fact Field Value with Work Item Parameter Columns

This implements an Action to set the value of a new Fact's field to that of a Red Hat JBoss Business Process Management Suite Work Item Handler's result parameter. Again, this Work Item needs to define a result parameter of the same data-type as a field on a bound fact type. You should then be able to set the field to the return parameter.
New Fact Field Value with Work Item Parameter column for Guided Decision Table Editor in BRMS User Guide 6.0.2

Figure 6.20. Set the value of a field on a new Fact with a Work Item parameter.

Note

Please note that in order to set the "Bind field to Work Item" option, you first need to have an Action executing a Work Item. This will allow you to insert a new Fact with a field value from a Work Item's Results.

6.4.6.5. Action BRL Fragment Columns

A construct that allows a BRL fragment to be used in the right-hand side of a rule. A BRL fragment is authored using the Guided Rule Editor and hence all features available in that editor can be used to define a decision table column. When using the embedded Guided Rule Editor, field values defined as "Template Keys" will form columns in the decision table. Facts bound in the BRL fragment can be referenced by the simpler column types and vice-versa.
A Simple Action BRL Fragment in the Guided Decision Table Editor for BRMS User Guide 6.0.2

Figure 6.21. Simple layout for Adding an Action BRL fragment

6.4.7. Rule Definition

Rules are created in the main body of the decision table using the columns that have already been defined.
Rows of rules can be added or deleted by clicking the plus or minus symbols respectively.
A screen shot of a decision table.

Figure 6.22. Rule Definition

6.4.8. Cell Merging

The icon in the top left of the decision table toggles cell merging on and off. When cells are merged, those in the same column with identical values are merged into a single cell. This simplifies changing the value of multiple cells that shared the same original value. When cells are merged, they also gain an icon in the top-left of the cell that allows rows spanning the merged cell to be grouped.
A table demonstrating the merging of cells.

Figure 6.23. Cell Merging

6.4.9. Cell Grouping

Cells that have been merged can be further collapsed into a single row. Clicking the [+\-] icon in the top left of a merged cell collapses the corresponding rows into a single entry. Cells in other columns spanning the collapsed rows that have identical values are shown unchanged. Cells in other columns spanning the collapsed rows that have different values are highlighted and the first value displayed.
This table shows how cells can be grouped using the +\- options.

Figure 6.24. Cell Grouping

When the value of a grouped cell is altered, all cells that have been collapsed also have their values updated.

6.4.10. Otherwise Operations

Condition columns defined with literal values that use either the equality == or inequality != operators can take advantage of a special decision table cell value of otherwise. This special value allows a rule to be defined that matches on all values not explicitly defined in all other rules defined in the table. This is best illustrated with an example:
when
  Cheese( name not in ("Cheddar", "Edam", "Brie") )
  ...
then
  ...
end
when
  Cheese( name in ("Cheddar", "Edam", "Brie") )
  ...
then
  ...
end