About Operators
Role: Administrator.
Minimum Version: Neurons for ITSM 2022.4.
Operators allow you to perform calculations, compare values, evaluate conditions, and manipulate data in expressions.
Supported Operators categories
The following categories of operators are supported:
- Arithmetic Operators: These operators are strictly used with numeric operands.
- Boolean Operators: These operators are used for operands that yield Boolean values (for example, values from logical fields, values from relational comparisons, etc.).
- Relational Operators: These operators are used with numeric operands for numerical comparisons. If one or both of the operands contain a string value, the type of comparison is instead based on lexicographical ordering.
- Equality Operators: These operators are used for testing for (non)equivalence for Boolean, DateTime, numeric, and text values.
- Bitwise Operators: These operators are used to perform Boolean operations on each bit of an integer.
- DateTime Interval Operators: These operators are used with the DateTime functions.
The operators supported in Neurons for ITSM are:
Category | Name | Operator |
|---|---|---|
Arithmetic | Addition | + |
Arithmetic | Subtraction | - |
Arithmetic | Multiplication | * |
Arithmetic | Division | / |
Arithmetic | Remainder | % |
Boolean | NOT | ! |
Boolean | AND | && or AND |
Boolean | OR | || or OR |
Relational | Less Than | < |
Relational | Greater Than | > |
Relational | Less Than or Equal | <= |
Relational | Greater Than or Equal | >= |
Equality | Equal | == or = or <> |
Equality | Not Equal | != |
Bitwise | AND | & |
Bitwise | OR | | |
Bitwise | Exclusive OR | ^ |
Bitwise | Complement | ~ |
Bitwise | Left shift | << |
Bitwise | Right shift | >> |
DateTime Interval | before | |
DateTime Interval | not before | |
DateTime Interval | during | |
DateTime Interval | not during | |
DateTime Interval | after | |
DateTime Interval | not after | |
Relational and equality operators
Relational and equality operators compare two expressions or values and return a Boolean value of true or false.
When comparing values, use compatible data types. If the operands have different data types, Neurons for ITSM might implicitly convert one of the values before performing the comparison. Implicit conversion can produce unexpected results, so explicit type conversion is recommended.
Comparing numeric values
Use a type-conversion function when the operands do not have the same data type. For example: $(number("6") >= 5)
The number function converts the text value "6" to a numeric value. The resulting comparison is: $(6 >= 5The expression returns true.
For information about the supported data types, see About Type Conversions.
Explicitly convert values when comparing different data types. This makes the intended comparison clear and helps prevent unexpected results.
Operator Precedence
The following table illustrates the order of precedence of the operators, from highest to lowest precedence.
Operators in the same row have the same precedence, which are evaluated from left to right, based on the appearance of the operators in the expression.
Category | Operators |
|---|---|
Boolean NOT | ! + (unary) - (unary) ~ The + (unary) and - (unary) operators are not the same as the + (additive) and - (additive) operators. |
Membership and DateTime interval | in not in before not before during not during after not after |
Multiplicative | * / % |
Additive | + - |
Left and right shift | << >> |
Relational / Equality | < > <= >= == != |
Bitwise AND | & |
Bitwise OR | | |
Bitwise Exclusive OR | ^ |
Boolean AND | && |
Boolean OR | || |
You can use parentheses to control precedence and associativity. When you save an expression, if you did not specify parentheses, the application automatically adds additional parentheses.
For example, if you enter the following expression:
$(3 + 4 * 5)
When you save it, the application displays the expression as:
$(3 + (4 * 5))
This is consistent with the order of precedence as shown in the previous table.
The Boolean operators (||, &&) are short circuiting:
- For expressions like $(Expr1 || Expr2), if Expr1 evaluates to true, then Expr2 is not evaluated.
- For expressions like $(Expr1 && Expr2), if Expr1 evaluates to false, then Expr2 is not evaluated.
For the Boolean AND (&&) and Boolean OR (||) operators, while defining the expression, you can opt to specify the operators as AND or OR, respectively. The application automatically converts them to && or || when you save the expression.
For example, if you define the if expressions as:
When you save the expressions, the application converts them to:
Binary Operators
Neurons for ITSM recognizes the following binary operators:
in, not in, before, not before, during, not during, after, not after, *, /, %, +, -, <<, >>, <, >, <=, >=, ==, !=, &, |, ^, &&, and ||
You can also use AND and OR instead of && and ||.
For example:
$(Status == "Closed" || Status == "Denied")
This conditional expression can be found as a read-only condition in the Layout Editor. If the value returned is true, then the status is closed and the form field becomes read-only. If the value returned is false, then the status is denied.
Prior to Neurons for ITSM Release 2015.2, you could use & instead of && and you could use | instead of ||.
Starting in Neurons for ITSM Release 2015.2, you can no longer use & and | in place of && and ||, as & and | are now used as bitwise operators.
If you have existing expressions that use & and | in place of && and ||, you must update them to use && and ||.
For example, when constructing an operator in the If block of the Workflow Designer, you can use binary operators:
- Enter a title in an If block. An example is Need additional approval.
- Select the OR radio button.
- Select a field as an operand. An example is Type of change.
- Apply an additional operator. An example is Not equal to (<>).
- Select a value. An example is Standard.
Based on the outcome of this expression, the exit port of the If block can connect to a different block, creating a different path within the workflow.
Boolean AND Bitwise Operators
The && (AND), || (OR), and ! (NOT) operators have Boolean operands and evaluate to a single Boolean value. && and || operators are short-circuiting, meaning that the right operand is not evaluated if the left operand determines the value result of the operator. This is only important if the right side expression has side effects, for example, in the case $(x && Prompt(...)).
The Prompt function is executed only when x is true. If x is false, the result of the && operator is always false regardless of the value of the Prompt function, and therefore the right operand is not executed in this case.
There are several new bitwise operators. Unlike the Boolean operators, these work on the individual bits of an integer value, treating a 0 it as false and 1 as true.
The bitwise operators are often useful in conjunction with hexadecimal literals, since the bit pattern of the resulting value is more apparent, for example, $(m & 0#f0f7).
Operator | Example | Description |
|---|---|---|
| | $(m | n) | Applies the OR Boolean operation to each bit of m with the corresponding bit of n. |
& | $(m & n) | Applies the AND Boolean operation to each bit of m with the corresponding bit of n. |
^ | $(m ^ n) | Applies the exclusive-OR Boolean operation to each bit of m with the corresponding bit of n. The exclusive-OR operation yields true if either of its left and right operands is true, but not both. |
~ | $(~m) | Applies the NOT Boolean operation to each bit of m. |
<< | $(m << j) | Shifts the value of m left i bits. If j is greater than the length of m, it will yield zero. |
>> | $(m >> j) | Shifts the value of m right i bits. If j is greater than the length of m, it yields zero. |
DateTime Interval Operators
DateTime interval operators consist of a pair of DateTime values that represent the start and end. They are often a calendar interval but do not have to be.
- after means after the end of the interval.
- not after means not after the end of the interval.
- before means before the beginning of the interval.
- not before means not before the beginning of the interval.
- during means during the interval.
- not during means not during the interval.
See Interval, Day, Week, Month, Quarter, and Year for information about built-in functions that use these DateTime interval operators.
About the In and Not In Operators
The in and not in operators can function on the server, on the client, and in Microsoft SQL queries.
The syntax is as follows:
- Text1 in ("one","two","three",...)
- Int2 in (3,33,333, ...)
The right side of the operator is a comma-separated list of values surrounded by parentheses. Starting in Neurons for ITSM Release 2015.2, the values do not need to be constants. Therefore, the following example is valid: Status in ("Open","Log"+"ged",Status).
You cannot include null in the list. For example, Status in (null,"Open") is not valid.
The right side of the in and not in operator expressions can also be any built-in function that computes a list. Currently, the only ways to compute a list are by using the built-in functions called CurrentUserTeamNames and CurrentUserTeamIds.
- The CurrentUserTeamNames function is now implemented on the client, on the server, and in Microsoft SQL queries, including in data segregation and in read-only and required rules. It appears in the function list in the expression editor for each of these kinds of expressions.
- The CurrentUserTeamIds function is only implemented on the server.
Therefore, expressions like $(OwnerTeam in CurrentUserTeamNames()) now work.
About Conditional Expressions
A conditional expression is a tool that lets you evaluate alternatives depending if a condition is true or false. You can enter conditional expressions using the if statement in the following syntax:
$(if condition then whenTrue else whenFalse)
This expression has three parameters:
- condition: The condition for which to test.
- whenTrue: The value to return if the condition is true.
- whenFalse: The value to return if the condition is false.
Neurons for ITSM only evaluates either the whenTrue or whenFalse value, based on the outcome of the condition.
You can nest if expressions within one another, so that the return value of one if expression feeds into another expression. It is most common to nest an if expression in the else part of another if expression. It is also possible to nest expressions in the then and else parts of the expression., but that is less common. In all cases, note that the Neurons for ITSM expression syntax $() applies to the outermost expression. You do not need to use the $() syntax anywhere within the nested expression.
Conditional Expression Examples
A conditional expression evaluates a condition and returns different values depending on whether the condition is true or false.
The following expression returns false if the incident status is Logged; otherwise, it returns true:
$(if Status == "Logged" then false else true)
You can use the return value of this expression to make the Owner field in the Incident business object required when the status is not Logged:
Owner is required when $(if Status == "Logged" then false else true)
The previous example returns a Boolean value (true or false). Conditional expressions can also return text values.
$(if Priority == "High" then "Urgent" else "Normal")
- High priority - Urgent
- Any other priority - Normal
You can use Boolean operators such as && (AND) and || (OR) to evaluate multiple conditions in a single expression.
$(if Urgency == "High" && Impact == "High" then "Critical" else "Standard")
- Urgency is High and Impact is High - Critical
- All other combinations - Standard
The following is a more complex example of a conditional expression. This expression is used in a default incident editing rule to determine the priority when the Urgency and Impact fields change:
In this example:
- High urgency + High Impact - Priority 1
- High urgency + Medium Impact, or Medium urgency + High Impact - Priority 2
- High urgency + Low Impact, Medium urgency + Medium Impact, or Low urgency + High Impact - Priority 3
- Medium urgency + Low Impact, or Low urgency + Medium Impact - Priority 4
- All other combinations - Priority 5
Using the Case Expression
There are two types of case expressions: Boolean AND value.
Boolean Case
The Boolean case expression is similar to an if-then-else statement.
For example, this statement:
case
when a > 0
then 44
when a < 0
then 22
else 11
is equivalent to this statement:
if a > 0 then 44 else if a < 0 then 22 else 11
In this example:
- If a is greater than 0, the expression returns 44.
- If a is less than 0, the expression returns 22.
- Otherwise, the expression returns 11.
The application executes the case statements in order. You can also nest case expressions, as in this example:
case
when a > 0 then case
when b > 0 then 11
when b < 0 then 22
else 33
when a < 0 then case
when b > 0 then 44
when b < 0 then 55
else 66
else case
when b > 0 then 44
when b < 0 then 55
else 66
Value Case
A value case expression compares a single value against multiple possible values and returns the result from the first matching when clause.
The application evaluates when clauses from top to bottom and returns the result from the first matching clause.
Unlike a Boolean case expression, which evaluates conditions, a value case expression compares one value to a list of possible values.
Use a value case expression when you want to evaluate a single field or value against multiple possible values and return a different result for each match.
$(case expression
when value1 then result1
when value2 then result2
...
else defaultResult)
Where:
- expression is the value being evaluated.
- Each when clause specifies a value to compare against.
- The corresponding then clause specifies the value to return when a match is found.
- The optional else clause specifies the value to return when no match is found.
Basic Example - The following example returns a label based on the value of Status:
$(case Status
when "Logged" then "New"
when "Active" then "In Progress"
when "Resolved" then "Completed"
else "Unknown"
)
This expression evaluates the Status value and returns the corresponding label for the first matching when clause.
Multiple Values Example - A single when clause can contain multiple values:
$(case Priority
when "High", "Critical" then "Urgent"
else "Normal"
)
In this example, both "High" and "Critical" return "Urgent".
Advanced Example - The following example calculates a priority value based on the values of Urgency and Impact:
$(case Urgency
when "High"
then (case Impact
when "High" then "1"
when "Medium" then "2"
else "3")
when "Medium"
then (case Impact
when "High" then "2"
else "3")
else "5")
In this example, the outer case evaluates Urgency, and the nested case evaluates Impact to determine the final priority value.
- The values in when clauses do not have to be constants.
- If multiple when clauses contain the same value, only one matching then expression is evaluated.
- If no when value matches, the else value is returned.
- If the else clause is omitted and no match is found, the expression generates an error.
