Skip to main content

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:

FeatureExample
Math operatorsprice * 1.2, quantity + 5, total / count
Comparisonsage >= 18, status == "active", price != 0
Logical operatorsage > 18 and status == "active", not isDeleted
Ternary operatorage >= 18 ? "adult" : "minor"
Functionsabs(balance), round(price, 2), max(score1, score2)
Object accessuser.name, items[0].price
Safe Evaluation

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

InputTypeDescriptionDefault
RunEventTriggers the evaluation of the Filtrex expression.-
CodeTextThe Filtrex expression to compile and execute. Access input data properties directly by name (e.g., price * quantity).-
DataDataThe data object to evaluate the expression against. Properties of this object are available as variables in the expression.-

Outputs

OutputTypeDescription
DoneEventFires when the expression has been evaluated successfully or an error occurs.
ResultDataContains 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:

  1. Compiles the Filtrex expression using filtrex.compileExpression()
  2. Executes the compiled function against the provided Data input
  3. Outputs the result to the Result output
  4. 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

PropertyDefaultDescription
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"
}