Expression

The expression is string literal that can evaluated to boolean value. For example this is string:

2+1 = 3

but from view point of evaluating, its value is true because in mathematic , number 2 plus number 1 is number 3, so first expression convert to 3 = 3 and because 3 is equal 3 then overall, expression evaluated true. Actually, in a expression, we try to convert symbols to values of symbols and then evaluate result to find out that it is true or false.

Expressions become so Practical when use with valuable. In fact valuables convert expression to dynamic valuable, that can use in many way. without variables, expression is a static or hard coded value. For example in:

A > 40

id variable A is more than 40, then evaluated result is true , but if it’s value is equal or less than 40 result id false

Operators

When you create comparison expressions, the following operators are allowed:

<
>
<=
>=
<>
=
IN
LIKE

The following arithmetic operators are also supported in expressions:

+ (addition)
- (subtraction)
* (multiplication)
/ (division)
% (modulus)

IN

Use IN For Find out presented value is one of the listed values or no. For example expression:

A IN ( 1 , 4 , 5)

Is true if variable A is 1 or 4 or 5. In other case result is false.

LIKE

Use this operator for string comparison with Wildcard Characters:

expression LIKE pattern
expression: string

The string to be evaluated.

pattern string

pattern to be searched.

For example in:

name LIKE 'ali'

If value name of is ali or ALI or aLi, result is true. In fact if Wildcard Characters not use in pattern, LIKE act like = operator. So name LIKE 'ali' is equal name = 'ali'. For complex pattern Wildcard Characters used. For example:

name LIKE '*i'

Say that result id true only if name value end with i. So ali or s.alI or i cause true result and alireza or reza generate false result. The * or % represent any occur of characters.

Note

string comparisons are case-insensitive.

Wildcard Characters

Both the * and % can be used interchangeably for wildcard characters in a LIKE comparison. If the string in a LIKE clause contains a * or %, those characters should be enclosed in brackets []. If a bracket is in the clause, each bracket character should be enclosed in brackets (for example [ or ]). A wildcard is allowed at the start and end of a pattern, or at the end of a pattern, or at the start of a pattern. For example:

userName LIKE '*ali*'
userName LIKE '*ali'
userName LIKE 'ali*'

Wildcard characters are not allowed in the middle of a string. For example, ‘te*xt’ is not allowed.

Functions

The following functions are also supported:

LEN

Gets the length of a string:

LEN(expression)
expression: string

The string to be evaluated.

For example:

Len(userName) > 12

Evaluated true if length of string value of variable userName ig grater than 12.

ISNULL

Checks an expression and either returns the checked expression or a replacement value:

ISNULL(expression, replacementvalue)
expression any

The expression to check.

replacementvalue any

If expression is null, replacementvalue is returned.

For example in:

IsNull(price, -1) > 10

If price value is null, -1 returned form IsNull function and evaluated value is false.

IIF

Gets one of two values depending on the result of a logical expression:

IIF(expr, truepart, falsepart)
expr any

The expression to evaluate.

truepart any

The value to return if the expression is true.

falsepart any

The value to return if the expression is false.

For example:

IIF(total>1000, 'expensive', 'dear') = 'dear'

TRIM

Removes all leading and trailing blank characters like r, n, t, ‘ ‘

TRIM(expression)
expression string

The expression to trim.

SUBSTRING

Gets a sub-string of a specified length, starting at a specified point in the string:

SUBSTRING(expression, start, length)
expression string

The source string for the substring.

start number

Integer that specifies where the substring starts.Base index is 0

length number

Integer that specifies the length of the substring.

For example:

SUBSTRING(phone, 0, 3) = '021'

Logical operators

For create complex an advanced expression, we can use operators like AND, OR and NOT. with this type of operators we can evaluate based on more than one condition. For example:

A > 40 AND A < 50

In this Example, expression become true if value of A become more than 40 and also less than 50. No other range acceptable. In face two sub-expression or condition A > 40 and A < 50 evaluated and then result of them AND together for generate final result. In below tables, see output of this operator for deferent inputs:

AND, OR Operators Sheet

Condition A

Condition B

OR

AND

True

True

True

True

True

False

True

False

False

False

False

False

False

True

True

False

NOT Operator Sheet

Condition A

NOT

True

False

False

True

The NOT operator use like this:

NOT(A = 3)

In above expression for all A values except 3, generate true and for 3 result is false.

Note

In expressions, operators or function is case insensitive. For example AND or And or and is equal.

Important

Because value of variable retrieved from [-sharp-sharp-notation injected to expression , if value has string type you must place variable inside ' or " form prevent syntax error.

For example suppose submitted form has name filed that has string value amir. In len([##cms.form.name##]) > 4 expression after inject value, expression is len(amir) > 4. This expression is invalid because now amir recognizing as new variable not string literal value.

For fix this problem, change original expression to len('[##cms.form.name##]') > 4. Now after injection, expression is len('amir') > 4 that is valid expression.