Hit Policies
The hit policy of a decision table is the letter in its top left cell. It says how many rules may match one input, and what the result is when several do. DMN distinguishes single hit policies, which return the outputs of one rule, and multiple hit policies, which return a list.
Overview
| Hit policy | Letter | Kind | Several rules match | Result |
|---|---|---|---|---|
| Unique | U | Single | Not allowed: an error | The one matching rule |
| Any | A | Single | Allowed if all give the same outputs, else an error | That output |
| Priority | P | Single | Allowed | The rule whose output comes first in the output values |
| First | F | Single | Allowed | The first matching rule, from the top |
| Output order | O | Multiple | Allowed | All matching rules, ordered by the output values |
| Rule order | R | Multiple | Allowed | All matching rules, in the order of the table |
| Collect | C | Multiple | Allowed | All matching rules, in any order |
| Collect with aggregation | C+, C<, C>, C# | Multiple | Allowed | The sum, minimum, maximum or count of the outputs |
Unique is the default when a table names no hit policy.
Single Hit Policies
Unique (U). Every input matches at most one rule. The rules must not overlap. This is the strictest and clearest policy: each rule can be read on its own, and an overlap is found as an error rather than hidden.
Any (A). Rules may overlap, but overlapping rules must give the same outputs. Useful when the same result has several independent reasons, for example approval needed because of the amount or because of the supplier.
Priority (P). Rules may overlap with different outputs; the output that comes first in the list of output values of the output wins. Example: output values "reject","review","accept" make reject win over review and accept.
First (F). Rules may overlap; the first matching rule from the top wins. Easy to write, especially with a last rule - for “anything else”, but the order of the rows becomes part of the logic, so a rule cannot be read on its own any more.
Multiple Hit Policies
Rule order (R). The outputs of all matching rules, as a list in the order of the rows. Example: all checks a request needs.
Output order (O). The outputs of all matching rules, as a list ordered by the output values, like Priority but keeping all of them.
Collect (C). The outputs of all matching rules as a list, in no defined order. With an aggregation, the list becomes one value:
| Aggregation | Letter | Result | Example |
|---|---|---|---|
| Sum | C+ | The sum of the outputs | Risk points of all matching rules |
| Minimum | C< | The smallest output | The shortest deadline |
| Maximum | C> | The largest output | The highest approval level |
| Count | C# | The number of matching rules | How many warnings apply |
An aggregation needs a table with one output, and for sum, minimum and maximum, a number.
Which Hit Policy Should I Use?
- One result, rules that never overlap: Unique. The default, and the easiest to check.
- One result, a fallback rule at the end: First, with
-in every cell of the last rule. - One result, the most severe one wins: Priority, with the output values in order of severity.
- All results: Rule order or Collect.
- A score or a count: Collect with
+or#.
In Flower BPM
Flower BPM evaluates every hit policy:
| Hit policy | Result in pi.decisions.<name> | No rule matches |
|---|---|---|
| Unique, Any, Priority, First | A context of the outputs, also for a table with one output: {"level": "gold"}. A decision that requires the table reads the value itself ("gold"), as in DMN | The default output entries as a context, else null |
| Output order, Rule order, Collect | A list of such contexts; a decision that requires a table with one output reads the list of values (["gold", "standard"]) | A list with the default output entries, else an empty list |
Collect with +, <, > | A number from the first output; empty values are left out. A value that is no number makes the result null, with a warning | The default output entry of the first output, else null |
Collect with # | The number of matching rules | 0 |
Priority and Output order need output values: a table with one of these hit policies and no output values on any output is refused with the error … but no output has output values: the priority of the rules is the order of the output values. Add them to an output, or use the hit policy FIRST (or RULE ORDER). An output value that is not in the list ranks last.
Unique with two matching rules and Any with different outputs are errors: when a business rule task runs the decision, the process instance gets an error comment that names the decision, the result is null, and the process goes on, so give the gateway after the task a default flow. Evaluate in the DMN modeler shows the same message, for example The decision “Discount” has the hit policy UNIQUE, but 2 rules match. See Decide with Decision Tables (DMN).