Step 1 — Define the facts
Facts are the step’s input: a flat object of keys and values..value is a naming convention that keeps related
keys apart — orderTotal.value and orderTotal.formatted are two independent
facts, not a nested object. The engine does not read the dot as a path.
In a real flow you would map facts in from earlier steps with
variable mapping rather than typing them:
$. expressions resolve before any rule runs.
Step 2 — Write a rule
1
The key
qualifiesForDiscount.value names the fact this rule produces. Later rules
can read it with @fact:qualifiesForDiscount.value.2
The operator
>= is greater than or equal. The name must come from the
operations reference exactly — a
typo produces no error, just a missing result.3
The input
An array of two values: the fact, and what to compare it against.
@fact:
is how a rule reads a fact.orderTotal.value of 75 you get false; with 100, true, because the
operator is >= rather than >.
Step 3 — Add the step to your flow
- Open the flow and add a Rules step.
- In Facts, map the values in from an earlier step, or paste the test facts above.
- In Rules, paste the rule JSON.
- Save, then use the play button in the editor toolbar to test the flow and check the step’s output.
Step 4 — Calculate the discount
Add two more rules. The second is an if/else ladder: an array of cells tried in order, where the first matching condition wins and the last cell — the one with no condition — is the default.orderTotal.value of 120:
75: false, 0, 75. With 100: true, 10, 90.
You did not have to order these rules. The engine reads the @fact: references,
works out that finalPrice depends on discountAmount which depends on
qualifiesForDiscount, and evaluates accordingly.
Step 5 — Use the result
The step emits a flat object of rule names to outcomes, exactly as shown above.Mistakes to watch for
A missing result instead of an error
A missing result instead of an error
An operator name the engine does not recognise fails the step and says which
rule and which operator. Several other mistakes give you nothing at all: a
ladder that matches nothing, a calculation that produces
NaN, an outcome of
null. The key is simply absent from the output. See
when a rule produces nothing.Forgetting the @fact: prefix
Forgetting the @fact: prefix
"input": ["orderTotal.value", 100] compares the literal string
"orderTotal.value" against 100. Write "@fact:orderTotal.value".Writing inputs instead of input
Writing inputs instead of input
The key is
input, singular. inputs is ignored and the operator runs with
no inputs at all — a comparison written this way returns false for every
value you give it.A ladder with no default cell
A ladder with no default cell
If none of the conditions matches and there is no final cell without a
condition, the rule produces no fact at all rather than a fallback value,
and nothing warns you.Passing between two separate bounds
Passing between two separate bounds
between takes its bounds as a nested array: [value, [low, high]]. Written
flat as [value, low, high] it returns false for every input, without
complaint.Quick reference
Dynamic valueWhat’s next
Core Concepts
Rule shapes, evaluation order, defaults, wildcards and failure modes.
Operations Reference
Every operator, with an executed example.
Common Patterns
Worked solutions to recurring problems.