Run Filtrex Code
Controlled node
Overview
The Run Filtrex Code node evaluates expressions written in Filtrex, a safe expression language for JavaScript. Unlike JavaScript's eval(), Filtrex allows you to execute mathematical and logical expressions without security risks, making it ideal for filtering, transforming, and calculating values from input data at runtime.
This node compiles the provided Filtrex expression and executes it against the input data object, returning the computed result.
Filtrex Expression Syntax
Filtrex supports a familiar syntax for data manipulation:
| Feature | Example |
|---|---|
| Math operators | price * 1.2, quantity + 5, total / count |
| Comparisons | age >= 18, status == "active", price != 0 |
| Logical operators | age > 18 and status == "active", not isDeleted |
| Ternary operator | age >= 18 ? "adult" : "minor" |
| Functions | abs(balance), round(price, 2), max(score1, score2) |
| Object access | user.name, items[0].price |
Filtrex expressions run in a sandboxed environment with no access to the global scope, eval(), or dangerous JavaScript features. This makes it safe to execute user-provided expressions.
Inputs
| Input | Type | Description | Default |
|---|---|---|---|
| Run | Event | Triggers the evaluation of the Filtrex expression. | - |
| Code | Text | The Filtrex expression to compile and execute. Access input data properties directly by name (e.g., price * quantity). | - |
| Data | Data | The data object to evaluate the expression against. Properties of this object are available as variables in the expression. | - |
Outputs
| Output | Type | Description |
|---|---|---|
| Done | Event | Fires when the expression has been evaluated successfully or an error occurs. |
| Result | Data | Contains the result of the expression evaluation. If an error occurs during compilation or execution, returns an object with an error property containing the error message. |
Runtime Behavior and Defaults
Compilation and Execution
When the Run event fires, the node:
- Compiles the Filtrex expression using
filtrex.compileExpression() - Executes the compiled function against the provided Data input
- Outputs the result to the Result output
- Fires the Done event
Error Handling
If the expression contains syntax errors or fails during execution, the node catches the error and outputs an object with an error property:
{
"error": "Invalid expression syntax near position 5"
}
Default Values
| Property | Default | Description |
|---|---|---|
expression | "" | Empty expression string (set via the node's code editor) |
Example
Filtering Data
Scenario: Calculate a discounted price based on quantity.
Inputs:
- Code:
quantity > 10 ? price * 0.9 : price - Data:
{
"price": 100,
"quantity": 15
}
Output:
- Result:
90(10% discount applied)
Complex Logic
Inputs:
- Code:
(score >= 80 and status == "active") ? "pass" : "fail" - Data:
{
"score": 85,
"status": "active"
}
Output:
- Result:
"pass"
Error Handling Example
Inputs:
- Code:
price *(incomplete expression) - Data:
{"price": 10}
Output:
- Result:
{
"error": "Unexpected end of expression"
}