Condition

Conditions are a type of Action that can be used to control when a Rule activates based on Boolean (true or false) comparisons. A condition is set as a property of an existing Rule.

Placing a Condition on a Rule

To place a condition on a rule, click on a rule to select it, then go to the Properties view's Condition panel. In the Actions panel, click and drag the condition onto the Condition panel's Condition field. Properties will appear under Inputs. Drag nodes from the Source and/or Target Schema sections to the Inputs section's Value fields, or hard-code Values to create the condition.

Since all conditions are true or false statements, you generally do not have to define a Return Assignment. However, if you want to use the condition result to affect a rule further down in the Ruleset, you will want to define a Return Assignment.

Note: Some Actions are Conditions, like if statements, and can only be used to condition an existing Rule, not to create a new one.

Examples

Examples of rules with conditions include:

  • For each Record: Source create a new Record: Target When GreaterThan [numberA=Quantity, numberB=0] -> []

    This Rule only writes a new record if the number in the Quantity field is greater than 0.

  • Move: [From=Color] -> [ColorCode] When Contains [text=Color, criteria=Purple] -> []

    This Rule only moves data from the Color node to the ColorCode node when the Color node contains the word Purple.

All conditions can be found in the Actions panel. Examples of some Conditions include HasContent, HasNoContent, EndsWith, NotEndsWith, Contains, NotContains, and Matches. A new set of Conditions are available when using the new transformatin engine. These include IsEmpty, IsNotEmpty, IsNull, IsNotNull, IsNullOrWhiteSpaces, and IsNotNullOrWhiteSpaces.

Composite Rules with conditions

When applying a condition to a Composite Rule it applies to all child Rules. Therefore, if you have a Composite Rule set to move data only if a condition is true, none of the child Rules will execute when the condition is false.

Suppose you are using the example: Move: [From=Color] -> [ColorCode] When Contains [text=Color, criteria=Purple] -> [] (only move data in the Color node to the ColorCode node when the Color node contains the word Purple). You want to make another Rule stating if the ColorCode node contains Purple, also move data from the Description source node to the Details target node.

Note: Because the result of a boolean condition is always true or false, to compare that result you would need a boolean variable that has the hard-coded value of true or false. Cleo recommends creating two generic hard-coded boolean variables (one named and coded True and one named and coded False) inside a Ruleset Data Object that is available to all Projects for instances like these.

For the first (Color) Rule's condition, create a variable (called IsConditionTrue) to hold the condition's result, and drag that variable under Outputs to the Return Assignments section.

Then, click on the second (Description) Rule you want to condition based on the first condition's results. From the Actions panel, drag the StringEquals condition to that Rule's Condition panel's Condition field. From the Variables panel, drag the IsConditionTrue variable under Inputs to stringA's Value field. Then drag the generic glb variable True to stringB's Value field.

The second Rule will look like this:

Move: [From=Description] -> [Details] When StringEquals [stringA=IsItTrue, stringB=True] -> []

Or, only move data from the Description node to the Details node when the string in the IsItTrue variable is true.