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.

**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**

**return a boolean value. These formulas can consist of:**

*must*- 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.

*if ( a == ZERO ) then**TRUE**else**end**a*is numericif

*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 numericif

*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.

## Business Use

- 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

- 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

- 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.

## Comments

0 comments

Please sign in to leave a comment.