Formulas

A Formula is an object used to create a statement that performs one or more calculations in a Ruleset.

Formulas allow users to manipulate data to return a value.

Examples of simple formulas include:
  • Addition: a + b
  • Concatenation: a cat b
  • Condition: If a == b then c else d end

Complex formulas build upon simple formulas to manipulate the data according to your needs.

Types

Clarify supports two formula types: Value and Logical.

Value formulas return either a string, boolean (true/false), numeric, or object value. These formulas can consist of:
  • a single variable
  • simple statements
  • complex statements
  • if/then/end statements
  • if/then/else/end statements
  • nested if/then/else/end statements
Logical formulas must return a boolean value. These formulas can consist of:
  • a single variable, which must be boolean
  • simple statements
  • complex statements

Structure

Write formulas in statements that combine variables with Formula Contents.

Multiple statements must be separated by the statement separator , (comma). If/then/else/end or if/then/end operators constitute a structure. At least one statement must be specified for the then.

Blanks must be entered between variables and operators.

Note: Cleo suggests thoroughly testing all formulas - even simple ones - before using them in a message class.
Examples of formulas include:
  • if ( a == ZERO ) then

    TRUE

    else

    end

    a is numeric

    if a equals 0, pass a true boolean result (to a node), if it does not, end

  • FALSE ,

    result = FALSE

    if ( a == ZERO ) then

    TRUE

    end

    The first two lines of this formula, FALSE and result = FALSE do the same thing; the first is shorthand for the second. They both set a default value in case a does not equal 0.

    The result is false unless a equals 0. If a equals 0, the result is true.

  • if ( a ) then

    b / c

    else

    b / c

    end

    a is boolean and sets a precedence override in this instance; b and c are numeric

    if a is true, divide b by c; if a is false, c remainder b

  • if ( numberA does_not_exist and numberB does_not_exist ) then

    FALSE

    else

    if ( numberA does_not_exist ) then

    TRUE

    else

    if ( numberB does_not_exist ) then

    FALSE

    else

    numberA <= numberB

    end

    end

    end

    if A and B do not exist, pass a false boolean result (to a node);

    if only A does not exist, pass a true;

    if only B does not exist, pass a false

    if both A and B exist and A is less than or equal to B, end.

    Note the presence of three ends, one for each else statement.

Note: To further your understanding, you may want to compare these formulas to the list of Formula Contents.

Business Use

This object is referenced from a Ruleset to generally condition rules. Common use cases may include:
  • Creating combined conditional expressions, such as: If Quantity * UnitPrice < 100, then execute Rule A ; but If Quantity * UnitPrice >= 100 , then execute Rule B .

How this Object Works

Clarify primarily uses Formulas to perform calculations or comparisons that:
  • Would otherwise require multiple Rules to perform
  • Can be set up once in a Formula, placed in your Core Project, then shared among multiple Projects.

Formulas can also be used to perform simple calculations the same way, for example, an Add Rule can, but their main purpose is to allow for more complex transformations.

Process Summary

To use this object, you must:
  • Create the object.
  • Define the object by setting numeric keys and values.
  • Reference from a Ruleset (as an Action).
    Note: Instead of using the Formula object, users can now write their own actions in Java. This object is no longer used in the new transformation engine. For more information see Using Custom Actions in the New Engine.