Define decision logic with Decision Tables

Decision logic defines how the output of each decision is derived from its inputs.

In DMN there are several ways to model decision logic. Currently, Cardanit supports decision tables to model decision logic. Decision tables are the most common form of decision logic, and the best suited to model complex logic. Its tabular layout helps you document all the possible conditions and results of a decision.

A decision table represents a set of related input and outputs, organized into rules that indicate which output entry applies to a specific set of input entries. It should only contain the inputs that are required to determine the output. A complete table contains all possible combinations of input values. In determining which rules to apply, the expressions defined in input clauses are evaluated for the given inputs and the expression results are then used to find rules with matching input entries.

A decision table consists of these elements:

  • An information item name: the name of the Decision or Business Knowledge Model that the decision table provides the decision logic for.

  • One or more inputs: a column in the table. It consists of an input expression (which contains an input value) and a list of input entries. Also known as an ‘input clause’.

  • One or more outputs: a column in the table. It’s the output that corresponds to a specific set of inputs. It has a name, a data type and an optional list of output entries. Also known as an ‘output clause’.

  • Input expressions: a column in the table. It contains the expression associated with a particular column or input. It usually corresponds with Decision or Business Knowledge Model the decision table provides the logic for.

  • Input entries: a cell in a row. They express a condition. There can be multiple entries in a input — one entry per rule.

  • Hit policy: displays the hit policy applied to the decision table.

  • Rules: rows in the table. Each row contains specific input entries and corresponding output entries. There can be multiple rules in a table.

  • Output entries: a cell in a row. They express a condition. There can be multiple entries in an output — one entry per rule.

  • Output expression: a column in the table. It contains the expression associated with a particular column or output. It usually corresponds with Decision or Business Knowledge Model the decision table provides the logic for.

  • Optional input or output values: an expression that defines a limited range of expected values for an input or output in a decision table.

Decision table elements

You configure decision tables in the Logic tab.

configuring a decision table in the Logic tab

Create a Decision Table

Decision and Business Knowledge Model elements support decision tables.

Decision tables are created in the Logic tab with a default input and output. You can add multiple inputs and outputs to the table.

You create decision tables in the Design tab.

To create a decision table:

  1. In the diagram, select a Decision or a Business Knowledge Model element.

  2. In the right-menu of the Ring, click .

    In the Design tab, the element you used to create the table will now display the decision table marker.

Define Decision Table inputs

Inputs are represented as columns. Every input can have multiple input entries.

You define an input in the Attributes panel.

To define an input:

  1. Select an input in the table.

  2. In the Panel menu, open Attributes.

  3. Define the input by completing these attribute fields:

    Attribute Description
    Description A description of the input. Optional.
    Input Expression Text The name of the input.
    TypeRef The data type of the input.
    Label A description of the input expression. Optional.
    Input Values Text Values can be FEEL expressions or defined data type values.

defining decision table inputs

Define Decision Table outputs

Outputs are represented as columns. Outputs can have several output entries.

You define an output in the Attributes panel.

To define an output:

  1. Select an output in the table.

  2. In the Panel menu, open Attributes.

  3. Define the output by completing these attribute fields:

    Attribute Description
    Output label The name of the output.
    Description A description of the output. Optional.
    TypeRef The data type of the output.
    Output Values Text Values can be FEEL expressions or defined data type values.
    Default Output Entry Text In an incomplete table, this lists output entries that can be set as default when no rules match.

defining decision table outputs

Add inputs and outputs

New inputs are added in the last Input column of the table. New outputs are added in the last Output column of the table.

If you’ve selected an existing input/output in the table, you’ll be give the option to add the new input/output to the right or left of the selected input/output.

To add an input or output to the decision table:

  1. In the toolbar, click Add Input or Add Output.

  2. Define the input/output in the Attributes panel.

Move inputs and outputs

You can change the order in which inputs and outputs appear in the column by moving them left or right.

  • In the toolbar, click Move Input or Move Output, then select Left or Right.

Delete inputs and outputs

  1. Select the input/output you want to delete.

  2. In the toolbar, click Delete Input or Delete Output.

Specify rules

Rules are expressed as rows within a table. Generally, a decision table will consist of multiple rules with every rule consisting of one or more input entries and a corresponding output entry.

Add a rule for each possible scenario of an input and output. The end result will be a decision table with all the relevant scenarios for the decision logic.

You can use FEEL expressions or any defined data type as entries. Make sure that the type of values you include is consistent with the data type of the input/output.

When you add a rule a new row is added at the bottom of the table. If you’ve selected a rule in the table, you’ll be given the option to add the new rule above or below the selected rule.

To add a rule:

  1. In the toolbar, click Add Decision Rule.

  2. In the Panel menu, open Attributes.

  3. Define the input and output entries by completing these fields:

    Field Description
    Text The value of the input/output entry.
    Description Optional. A description of the input or output entry.

Move a rule

You can change the order in which rules appear in the table by moving them up or down.

  • In the toolbar, click Move Rule, then select Up or Down.

Delete a rule

  1. Select the rule you want to remove.

  2. In the toolbar, click Delete Rule.

Define a Hit Policy

A decision table usually has several rules. If these rules overlap — more than one rule matches a given set of input values — a hit policy selects the proper output value. The output value can be a single value or a list of values.

There are two types of hit policies: Single Hit and Multiple Hit.

Single hit policies produce one result per input. Only one rule is applied at a time, even if several rules exist.

Multiple hit policies produce a list of outputs. All applicable rules are considered regardless of their position in the table. The resulting output can be a list or aggregated to a single value.

These are the hit policies:

Type Hit policy Description
Single Hit UNIQUE (U) Only one rule can match. Overlapping rules represent an error. The default hit policy when you create a decision table.
FIRST (F) Overlapping rules may have different output values. The hit policy selects the first matching rule.
PRIORITY (P) Overlapping rules may have different output values. The hit policy selects the one with the highest priority, which is determined by the order of allowed values in the table output column heading.
ANY (A) Rules may overlap, but only if their output values are the same. Overlapping rules with different output values mean the table is inconsistent and incorrect.
Multiple Hit COLLECT (C) Collects the outputs of matching rules, but can be configured to determine the sum, minimum, maximum, or count of matching outputs instead.
RULE ORDER (R) Results are ordered by the order of matching rules.
OUTPUT ORDER (O) Results are ordered by the priority of the output values.

Define the Hit Policy

  1. In the Panel menu, click Attributes.

  2. In Hit Policy, click and select the policy from the dropdown list.

View the logic list

The logic list enables you to explore all the decision tables in a model. The list is divided into two sections — Decisions and Business Knowledge Models.

To view the logic list:

  • In the Panel menu, click Logic List.

navigating the Logic list

Delete a Decision Table

  1. In the Design tab, select the Decision or a Business Knowledge Model element displaying the icon, and in the right-menu of the Ring, click .

  2. In the dialog box that opens, click Delete.