Mastering Expressions in RCOM Gateway Workflows
Expressions are a core mechanism in RCOM Gateway workflows, especially in Condition Action blocks, enabling dynamic evaluation of conditions and parameter values. They allow you to build logic directly into workflow actions without requiring a full script.
Unlike scripts, which are full lists of statements, an expression always produces a single return value of a defined type. This makes expressions ideal for use in condition blocks, action parameters, and variable mappings.
Where Expressions Are Used
Expressions in RCOM Gateway appear anywhere a workflow or event processor requires a value that is calculated at runtime instead of entered statically. They are the glue between incoming event data, workflow logic, and action outputs.
Key usage areas include:
-
Condition Blocks Used to evaluate a boolean expression that decides the execution path (e.g., whether to follow the
TrueorFalsebranch). -
Action Parameters Many workflow actions allow parameters to be set dynamically. For example:
- Constructing a URL string in an
HttpRequestaction. - Performing numeric calculations before storing a value in
SetVar. - Applying filters in object queries.
- Constructing a URL string in an
-
Variable Assignments The
SetVaraction supports assigning expressions, letting you compute values from existing workflow context variables instead of hardcoding them. -
Event Processor Variable Mapping When configuring an
Event Processor, incoming event payload fields can be transformed using expressions before being passed to workflow parameters. -
Looping and Iteration Blocks Actions like
WhileorForEachuse expressions to determine conditions or to select items within lists and dictionaries.
In short, expressions let you embed business logic directly into workflow design without dropping into full scripting, balancing flexibility with simplicity.
Expression Types and Examples
Expressions follow a C#-like syntax and support a wide range of operations.
Suppose:
| Variable | Type | Content |
|---|---|---|
| myInt | int | 15 |
| myString | string | Mat4711 |
| myList | List<int> | 1,1,2,3,5,8 |
| myDic | Dictionary<string, string> | Name=Peter, Age=20 |
1. Conditional
myInt > 10 ? "yes" : "no"
Returns "yes" if myInt is greater than 10, otherwise "no".
2. Logical Operators
myInt > 10 OR myInt < 10 // true
myInt > 10 AND myInt < 10 // false
NOT(myInt > 10) // false
Supported: AND, OR, NOT.
3. Equality and Comparison
myString == "Mat4711" // true
myInt != 15 // false
myInt >= 10 // true
myInt <= 15 // false
Useful for condition checks.
4. Type Checks
myInt is int // true
myInt is string // false
Ensures type safety at runtime.
5. Mathematical Operations
myInt + 10 // 25
myInt * 10 // 150
myInt % 6 // 3
-myInt // -15
Expressions support integer and decimal math.
6. String Operations
myString + myString // "Mat4711Mat4711"
myString + myInt.ToString() // "Mat471115"
myString.Substring(2) // "t4711"
Concatenation and string methods are supported.
7. Instantiation
new list<string> // returns empty list (List<string>)
new dictionary<string,object> // returns empty dictionary (Dictionary<string, object>)
Useful for creating fresh collections at runtime.
8. Index Access
myList[0] // 1 (int)
myList[1] // 1 (int)
myList[2] // 2 (int)
myDic["Name"] // "Peter" (string)
myDic["Age"] // "20" (string)
Works with List<T> and Dictionary<TKey, TValue>.
9. Property Access
myString.Length // 7 (int)
myList.Count // 6 (int)
Directly retrieves object or collection properties.
10. Method Calls
myInt.ToString() // "15" (string)
myString.PadLeft(10) // " Mat4711" (string)
myString.PadLeft(10, "0") // "000Mat4711" (string)
myString.Substring(2) // "t4711" (string)
Instance methods are supported on primitive and collection types.
11. Variable Access
myInt // 15 (int)
myString // "Mat4711" (string)
12. Function Calls
DateTimeUtcNow() // current UTC time (DateTime)
NewGuid() // random UUID (Guid)
myString.Substring(2) // t4711 (string)
Global functions return system values useful for workflow logic.
13. Literals
35 // 35 (int)
"35" // "35" (string)
0xA // 10 (byte)
0.5 // 0.5 (decimal)
.5 // 0.5 (decimal)
true // true (bool)
false // false (bool)
null // null (object)
Evaluation Order
Expressions are resolved using operator precedence. Brackets can override the default order:
- Multiplication > Addition
- Logical AND > Logical OR
- Unary operators > Binary operators
Examples:
| Variable | Type | Content |
|---|---|---|
| a | bool | true |
| b | bool | false |
| c | bool | false |
| myInt | int | 15 |
-
Multiplication > Addition
myInt * 2 + myInt // 45 (int)
myInt * (2 + myInt) // 255 (int)
-
Logical AND > Logical OR
a OR b AND c // true (bool)
(a OR b) AND c // false (bool)
-
Unary operators > Binary operators
-myInt + 16 < 0 // false (bool)
-(myInt + 16) < 0 // true (bool)
NOT a AND b // false (bool)
NOT (a AND b) // true (bool)
Brackets should be used liberally for clarity, especially in complex logical conditions.
Best Practices
- Always ensure expressions return the expected type (e.g., boolean for conditions, string for concatenations).
- Use brackets to make evaluation explicit, especially for complex logical conditions.
- Prefer expressions for simple transformations; use
CustomScriptactions when multiple statements or loops are required. - Debug using
Workflow ContextandLogsto verify evaluated values at runtime.