Skip to content

Element <rule>

Purpose: Conditionally execute a rule action in the current data context.

Why: Use it for a conditional in-context assignment that is clearer as an explicit rule, or set then='False' to discard the current record when the condition matches.

Example

1
<rule if="customer.is_adult" then="customer.status = 'adult'"/>

Decision guide

Business value: Represents a conditional business assignment or record-filtering decision as an explicit rule in the current context.

  • Use when

    • One named condition and action are clearer than a broader branch or mapping pipeline.
    • A matching record must be discarded by setting then='False'.
  • Choose another approach when

    • The requirement is row validation, multi-step branching, or ordinary field generation.
  • Prerequisites

    • Ensure every value referenced by the condition and action is already in scope.
  • Alternatives

    • Use mapping for ordered source-transformation assignments. (See: <mapping>)
    • Use condition when several child statements form each branch. (See: <condition>)

Complete examples

Assign a field only when an explicit business rule matches

Use rule for a conditional in-context assignment inside a control-flow branch; use mapping for the normal ordered source-transformation pipeline.

conditional-assignment/datamimic.xml
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
<setup>
    <generate name="decisions" count="2" target="LogExporter">
        <key name="id" generator="IncrementGenerator"/>
        <key name="risk_score" script="20 if id == 1 else 80"/>
        <condition>
            <if condition="True">
                <rule if="risk_score >= 50" then="decision = 'review'"/>
                <rule if="50 > risk_score" then="decision = 'approve'"/>
            </if>
        </condition>
    </generate>
</setup>

Rules and invalid combinations

No additional element-specific rules. Required attributes, types, and supported values are shown below.

Allowed parents / Allowed children

Allowed parents: else, else-if, generate, if, iterate, nestedKey, while

Allowed children:

None

Attributes

Show all 2 attributes

if

Condition to evaluate.

required; string.

then

Action to take if condition is true; literal False discards the current record.

required; string.