Expressions
Expressions are used in IF and SNIPPET actions. Refer to the script examples in those topics to see how expressions are correctly used.
An expression is a statement that is evaluated to be true or false. The following is a typical expression to compare the variable "customer" with a string of text:
customer = "Mary Joe"
When evaluated as an expression, it results in a True or False value. When customer contains the exact value "Mary Joe", the result will be True. For any other value, the result will be False. The most common action to make use of expressions is called IF, which is found in the Advanced tab and contains one property: Expression. The previous example can be entered into the Expression property. When the application runs, the value of customer will be compared with the string "Mary Joe". If it matches, the result condition True will be followed.
Here is an example from a script that makes use of IF:
The IF action properties would look like:
When working with expressions, it is important to remember that the equal sign (=) does not assign a value to the variable on the left side of the expression. In algebra and in other programming languages, it is common to represent a variable assignment by using the equal sign: x = 2 * y - 3. This algebraic expression suggests that x will take on the value of 2 * y - 3. If this same expression were used in the IF action, the variable x would be compared with the value of 2 * y - 3.
To change the value of a variable, use the ASSIGN action instead. We discussed ASSIGN previously when discussing Variable Substitution. In order for ASSIGN to be used to evaluate expressions, one of ASSIGN's other properties must be changed.
Now the variable x will take on the result of 2 * y - 3 because the property Type has been changed to Numeric. A drop-down list reveals the possible choices. String, Numeric and Date Time are recognized types. When dealing with Numeric Types, only expressions are allowed. Variable Substitution no longer works.
Since an expression can be as simple as a number, the following examples are technically identical:
If the both Values were changed to "100234 + 15", the two would no longer be the same. The left side would compute the sum of 100234 and 15, or 100249, while the right side would store the literal string "100234 + 15" into abc.
For a complete list of logical and arithmetic operators, click here.