Expressions can be used in process definitions for evaluating the following conditions:
validating variable values at the completion of a task
checking whether a transition should be traversed or not
checking whether an iteration has completed or not
Expressions are evaluated using the variable values and a scripting
language which is BeanShell by default. BeanShell uses Java syntax
for expressions. However, because expressions are specified in XML
files, BeanShell also supports special syntax for characters (such
as &, <, > and so on) that are not allowed in XML. Table 2: Syntax for Logical Operations shows the syntax for logical expressions
and Table 3: Syntax for Arithmetic Operations shows arithmetic expressions
syntax.
Table 2: Syntax for Logical Operations
| Logical Operation | Syntax |
|---|---|
| and | @and |
| or | @or |
| not | ! |
| not equal to | != |
| equal to | == |
| greater than (>) | @gt |
| greater than equal to (>=) | @gteq |
| less than (<) | @lt |
| less than equal to (<=) | @lteq |
Table 3: Syntax for Arithmetic Operations
| Arithmetic Operation | Syntax |
|---|---|
| addition | + |
| multiplication | * |
| integer or real division | / |
| modulo | % |
While defining expressions you should be aware of how the values of variables are represented, and the operations that are supported on them.
For Boolean variables @and, @or, !, == and != operations
are allowed.
For example if x and y are two Boolean variables then
the expression x @and y will evaluate to true
only if both x and y are true. The expression x @or !y will evaluate to true if either x is true
or y is false. The previous expression can
also be specified as: x == true @or y == false.
For Long and Double values @gt, @gteq, @lt, @lteq, +, *, / and % operations are allowed.
For example if x and y are two Long variables then the expression x @lt 2*y will
evaluate to true if the value of x is less
than double of y.
String variables are represented
as instances of java.lang.String, which does
not support any operations.
For string comparisons you
should use the equals() method instead of logical
operators such as == or !=. For example if x and y are two String variables then the expression x == y will not evaluate to true even if the value of x and y are the same. You must
use the expression: x.equals(y). String literals
can also be used in expressions by putting them under double quotes
(“”). If you use literals within
the expression then you must use single quotes for the expression.
For example the expression 'x.equals(“Hello World”)' will evaluate to true if the value of x is Hello World.
Reference variables are represented
as instances of ModelObjectInterface which
belongs to EKM's scripting interface. See Using EKM's Scripting Interface in the Defining Macros
chapter to learn more about EKM’s scripting interface.
You can use any of the methods defined in ModelObjectInterface on the reference variable instance, such as getName(), getProperties(), and so on.
For example, if x is a reference variable
the expression ‘x.getName().equals(“foo”)’ will evaluate to true if the reference points to an object whose
name is foo. For checking whether the reference
is valid or not, you should compare it to the void keyword. For example,
the expression x == void returns true is the
reference variable x points to an object that
does not exist.
Date variables are represented
as instances of java.util.Date class. You
cannot use logical operations such as < > or == with dates. However, you
can use after(), before() or equals() methods of the Date class to compare one date with another.
Multi-valued variables are represented as an array
of objects. Each object can be of type Boolean, Long, Double, String, Date or ModelObjectInterface.
For example, if x is a multi-valued String variable that has values a, b and c then in expressions
this variable is available as the list: [“a”, “b”, “c”].
Usually you will use multi-valued variables in expressions under the
following conditions:
To determine the number of values specified.
For example, the expression x.length > 2 will evaluate to true if x has more than
2 values specified.
To determine whether the list contains a particular value.
Because Java arrays do not provide a direct method for checking whether an element is contained within the array, you could use a macro in this case. An example of this is provided later.
You can also use parenthesis for grouping sub-expressions, for example:
x @lt 2*y @and (x @lt 10 @or x @gt 20)