- 25 Nov 2024
- 4 Minutes to read
- Print
- DarkLight
IMCScript operators
- Updated on 25 Nov 2024
- 4 Minutes to read
- Print
- DarkLight
Operators are special symbols that perform specific actions on one to three operands.
Arithmetic operators
Addition (+)—Sums numeric operands. Concatenates string operands.
var sum = 5 + 4; // 9 var greet = "Good " + "Morning"; // "Good Morning"
Substration (-)—Produces the difference between (subtracts) numeric operands.
var diff = 15 - 5; // 10
Multiplication—Multiplies numeric operands.
var mul = 4 * 3; // 12
Division—Produces the quotient of numeric operands where the left operand is the divident and the right operand is the divisor.
var div = 18 / 6; // 3
Modulus (%)—Produces the remainder of numeric operands, where the left operand is the divident and the right operand is the divisor.
var mod = 17 % 5; // 3
Logical operators
- Logical AND (&& / and)—Performs logical AND between operands.
- Logical OR (|| / or)—Performs logical OR between operands.
- Logical Not (!)—Performs logical NOT for the operand.
Bitwise operators
- Bitwise AND (&)—Performs Bitwise AND between operands. At the binary level, it returns 1 in each bit position for which the corresponding bits of both operands are 1s.
var bitwiseAnd = 33 & 4; // Outcome: 0 (0010 001 & 000 0100 = 0000 0000 = 0)
- Bitwise OR (|)—Performs Bitwise OR between operands. At the binary level, it returns 1 in each bit position for which the corresponding bits of either or both operands are 1s.
var bitwiseOr = 33 | 4; // Outcome: 37 (0010 001 | 0000 0100 = 0010 0101 = 37)
- Bitwise NOT (~)—Performs Bitwise NOT (or complement) for an operand. At the binary level, it inverts the bits of an operand.
var bitwiseNot = ~33; // Outcome: -34 (~0010 0001 = 1101 1110 = -34)
- Bitwise XOR (^)—Performs Bitwise XOR between operands. At the binary level, it returns 1 in each bit position for which the corresponding bits of either (but not both) operands are 1s.
var bitwiseXor = 34 ^ 4; // Outcome: 36 (0010 0000 ^ 0000 0100 = 0010 0100 = 36)
Conditional operators
Equality (=)—Compares equality between operands.
var num1 = 5; var num2 = 6; var num3 = 5; var result = num1 == num2; // Outcome: false var result2 = num1 == num3; // Outcome: true
Inequality (!=)—Compares inequality between operands.
var bool1 = true; var num = 6; var num2 = 5; var result = num < num2; // Outcome: true var result2 = num2 < num ; // Outcome: false
Less Than (<)—Returns
true
if the left side operand is less than the right operand; otherwise returnsfalse
.var num = 10; var num2 = 20; var result = num < num2; // Outcome: true var result2 = num2 < num ; // Outcome: false
Less Than or Equal To (<=)—Returns
true
if the left side operand is less than or equal to the right operand; otherwise returnsfalse
.var num = 10; var num = 10; var result = num <= num2; // Outcome: true var result2 = num2 <= num ; // Outcome: true
Greater Than (>)—Returns
true
if the left side operand is greater than the right operand; otherwise returnsfalse
.var num = 10; var num2 = 20; var result = num > num2; // Outcome: false var result2 = num2 > num ; // Outcome: true
Greater Than or Equal To (>=)—Returns
true
if the left side operand is greater than or equal to the right operand; otherwise returnsfalse
.var num = 10; var num2 = 10; var result = num >= num2; // Outcome: true var result2 = num2 >= num ; // Outcome: true
Ternary(? :)—The ternary operator is a short-hand operation of simple if-else statements. If the condition can be converted to
true
, the operator returns a value ofexprT
; otherwise it returns a value ofexprF
.Syntax:
condition ? exprT : exprF
var result = 5 > 4 ? 100 : 0; // Outcome: 100
Recursive traversal operators
These special operators are similar to RegEx + and *. They apply only to IMCExpression intermediate steps.
Recursive Plus (<intermediate_steps>_)—Same as the + operator in RegEx. It provides one or more levels of recursive traversal on IMCExpression intermediate steps. To use it, add _ (underscore) at the end of the intermediate step.
// Test123 (Quote) // | // --- "Open Field Project" (SalesItem) // | // --- "Infield" (SalesItem) // ["Open Field Project"] var oneLevelSalesItems = Quote().includesSalesItem.objectName; // ["Open Field Project", "Infield"] var allLevelSalesItems = Quote().includesSalesItem_.objectName;
Recursive Star (<intermediate_step>)—Same as the * operator in RegEx. It provides zero or more levels of recursive traversal on IMCExpression intermediate steps. To use it, add _ (underscore) at the start and end of the intermediate step.
// Test123 (Quote) // | // --- "Open Field Project" (SalesItem) // | // --- "Infield" (SalesItem) // ["Open Field Project] var oneLevelSalesItems = Quote().includesSalesItem.objectName; // ["Test123", "Open Field Project", "Infield"] var allLevelSalesItems = Quote()._includesSalesItem_.objectName;