Operator Reference

You can use operators to perform calculations and comparisons within expressions. For example, ${af:getDay(system.time) == 1} returns true if the function’s output is the first day of any month, and false otherwise.

You can use the following operators in expressions:

  • Arithmetic: + - (binary and unary) * / div mod
  • Conditional: ? : (as in A ? B : C)
  • Relational: == eq != ne < lt > gt <= le >= ge
  • Logical: and && or || not !
  • Empty: empty

You can use parenthesis to change the precedence of the operators; for example, in the following expression:

${(user.quiz1 + user.quiz2) / 2 <= 8}

MEP will evaluate the section (user.quiz1 + user.quiz2) before evaluating the rest of the expression.

The precedence of operators from highest to lowest, left to right is as follows:

  • ( ) used to change the precedence of operators, for example 4 * (1 + 2)
  • - (unary) not ! empty
  • / div % mod
  • + - (binary)
  • < > <= >= lt gt le ge
  • == != eq ne
  • && and
  • || or
  • ? :

Arithmetic operators

Operator

Description

+

Adds two numerical values together; for example, the expression ${ 1 + 2} evaluates to 3.

As a unary operator it indicates a value is a negative, for example: -3.

As a binary operator it subtracts one value from another, for example: ${user.example – 1}.

*

Multiples the values together; for example, the expression ${3*4} evaluates to 12.

/ or div

 

Divides the values to get the quotient, for example: ${10 div 4} which returns 2.5. This will return a floating point number for very large numbers or numbers with fractional parts.

% or mod

 

Divides the values to get the remainder, for example: ${12 % 10} which returns 2. If the value being divided is a floating point number, then this operator will return a floating point number.

Conditional and relational operators

Relational operators enable you to compare values, including Boolean, string, integer, or floating point values.

For string values, the operators compare the values alphabetically, where Z is higher than A. For example, the following expressions would all return with the value true:

  • ${"apple" == "apple"}
  • ${"pear" < "pears"}
  • ${"apples" <= "applez"}

The letters are separated by case, where the full range of upper case letters (A-Z) are of lower value than lower case letters (a-z). This means that Z is a lesser value than a.

Operator

Description

== or eq

Returns with true if the values equal one another, and false otherwise. For example, the expression, ${af:random(2) == 1} returns true if the random number generated is 1, and false otherwise.

!= or ne

Returns with true if the values do not equal one another, and false if they do. For example, the expression, ${12 != 10} returns true.

< or lt

Used in the format A < B, where the output returns true if the value of A is smaller than the value of B. If A and B are the same value, or if A is greater than B, then the output returns false.

> or gt

Used in the format A > B, where the output returns true if the value of A is greater than the value of B. If A and B are the same value, or if B is greater than A, then the output returns false.

<= or le

Used in the format A <= B, where the output returns true if the value of A is equal to or less than the value of B. If A is a greater value, then the output returns false.

>= or ge

Used in the format A >= B, where the output returns true if the value of A is equal to or greater than the value of B. If A is a smaller value, then the output returns false.

? :

Used in the format A ? B : C, where the output is either B or C, depending on the result of the evaluation of A. If the value of A is true, then the left value B is chosen; otherwise the right value C is chosen. For example, the expression: ${af:random(2) == 1 ? 'left' : 'right'} checks whether the output of the function random(2) is equal to the value 1 and outputs the value left if it does match or right if it doesn’t match.

Logical operators

Operator

Description

and or &&

Returns with true if the values are all true, and false if any of the values are false. For example, in the following expression:

${user.AnswerA == "CAT" && user.AnswerB == "MOUSE"}

The expression returns true only if user.AnswerA equals CAT and user.AnswerB equals MOUSE. It will return false if either or both of the values are false.

or or ||

Returns true if one or more of the values is true. For example, in the following expression:

${request.keyword.name == "CAT" || request.keyword.name == "DOG" || request.keyword.name == "FISH"}

Then the value will return true if an end user has texted in either CAT, DOG or FISH, and false if none of these words were found as the keyword.

not or !

 

Returns with true if the value is false. For example, in the following expression:

${not user.GameTotal <= 11}

If user.GameTotal is less than or equal to 11, then the expression returns false. In the expression: ${not empty user.example}, the expression returns true when the variable value is not empty.

Empty operator

Operator

Description

empty

 

Empty evaluates to a Boolean (true or false) value. If the value is null, then the value returned is true. For example, the expression ${empty user.example} checks whether there is a value in the custom variable user.example for an end user, and returns true if there is no value. Alternatively you could use ${not empty user.example} so that the expression returned true when the variable value is not empty.

Note that if a variable you are checking does not exist, or you have entered an empty string such as "", then the value is also considered null.