Skip to main content

Expressions

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 True or False branch).

  • Action Parameters: Many workflow actions allow parameters to be set dynamically. For example:

    • Constructing a URL string in an HttpRequest action.
    • Performing numeric calculations before storing a value in SetVar.
    • Applying filters in object queries.
  • Variable Assignments: The SetVar action 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 While or ForEach use expressions to determine conditions or to select items within lists and dictionaries.

  • Custom scripts: Custom script executes scripts using the built-in RCOM Gateway Interpreter, and these scripts can leverage expressions to perform dynamic operations inside workflows.

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:

VariableTypeContent
myIntint15
myStringstringMat4711
myListList<int>1,1,2,3,5,8
myDicDictionary<string, string>Name=Peter, Age=20

1. Conditional

1myInt > 10 ? "yes" : "no"

Returns "yes" if myInt is greater than 10, otherwise "no".

2. Logical Operators

1myInt > 10 OR myInt < 10   // true
2myInt > 10 AND myInt < 10  // false
3NOT(myInt > 10)            // false

Supported: AND, OR, NOT.

3. Equality and Comparison

1myString == "Mat4711"   // true
2myInt != 15             // false
3myInt >= 10             // true
4myInt <= 15             // false

Useful for condition checks.

4. Type Checks

1myInt is int       // true
2myInt is string    // false

Ensures type safety at runtime.

5. Mathematical Operations

1myInt + 10     // 25
2myInt * 10     // 150
3myInt % 6      // 3
4-myInt         // -15

Expressions support integer and decimal math.

6. String Operations

1myString + myString             // "Mat4711Mat4711"
2myString + myInt.ToString()     // "Mat471115"
3myString.Substring(2)           // "t4711"

Concatenation and string methods are supported.

7. Instantiation

1new list<string>                        // returns empty list (List<string>)
2new dictionary<string,object>           // returns empty dictionary (Dictionary<string,object>)

Useful for creating fresh collections at runtime.

8. Index Access

1myList[0]       // 1 (int)
2myList[1]       // 1 (int)
3myList[2]       // 2 (int)
4myDic["Name"]   // "Peter" (string)
5myDic["Age"]    // "20" (string)

Works with List<T> and Dictionary<TKey, TValue>.

9. Property Access

1myString.Length   // 7 (int)
2myList.Count      // 6 (int)

Directly retrieves object or collection properties.

10. Method Calls

1myInt.ToString()             // "15" (string)
2myString.PadLeft(10)         // "   Mat4711" (string)
3myString.PadLeft(10, "0")    // "000Mat4711" (string)
4myString.Substring(2)        // "t4711" (string)

Instance methods are supported on primitive and collection types.

String Split Methods

The SplitLength and SplitPart methods allow you to split strings and access specific parts:

1TOPIC.SplitPart("/", 1) == "1234"        // access part at index
2TOPIC.SplitLength("/") >= 2 AND TOPIC.SplitPart("/", 1) == "1234"  // safe check with length

Separator behavior:

  • If the separator string is empty: returns 0 for SplitLength or empty string for SplitPart.
  • If the separator has 1 character: uses the .NET Split(char) function.
  • If the separator has 2+ characters: uses the .NET Split(char[]) function with individual characters as separators.
info

Use SplitLength to check the split result count before calling SplitPart to prevent index out of range errors.

11. Variable Access

1myInt       // 15 (int)
2myString    // "Mat4711" (string)

12. Function Calls

1DateTimeUtcNow()   // current UTC time (DateTime)
2NewGuid()          // random UUID (Guid)
3myString.Substring(2)  // "t4711" (string)

Global functions return system values useful for workflow logic.

13. Literals

135       // 35 (int)
2"35"     // "35" (string)
30xA      // 10 (byte)
40.5      // 0.5 (decimal)
5.5       // 0.5 (decimal)
6true     // true (bool)
7false    // false (bool)
8null     // 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:

VariableTypeContent
abooltrue
bboolfalse
cboolfalse
myIntint15
  • Multiplication > Addition
1myInt * 2 + myInt       // 45 (int)
2myInt * (2 + myInt)     // 255 (int)
  • Logical AND > Logical OR
1a OR b AND c            // true (bool)
2(a OR b) AND c          // false (bool)
  • Unary operators > Binary operators
1-myInt + 16 < 0         // false (bool)
2-(myInt + 16) < 0       // true (bool)
3NOT a AND b             // false (bool)
4NOT (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 CustomScript actions when multiple statements or loops are required.
  • Debug using Workflow Context and Logs to verify evaluated values at runtime.