Skip to main content

Function

This node executes custom JavaScript code.

The Function (JavaScriptFunction) node allows for complex logic and data transformation using code.

The Function node provides a sandbox for writing JavaScript. Unlike the Expression node which is for single-line formulas, this node supports full function bodies, multiple inputs/outputs, and asynchronous operations.

Inputs

General

DataDescription
ScriptThe JavaScript code to execute.

Actions

SignalDescription
RunTriggers the script execution.

Dynamic Inputs

DataDescription
in-*Inputs defined in the script (e.g., Inputs.myVar) appear as ports here.

Outputs

Dynamic Outputs

DataDescription
out-*Outputs defined in the script (e.g., Outputs.result = ...) appear as ports here.

Usage

Writing Scripts

The script runs inside an async function.

  • Access inputs via Inputs.portName.
  • Set outputs via Outputs.portName = value.
  • Trigger output signals via Outputs.signalName().

Example:

// Calculate total and tax
const total = Inputs.price * Inputs.quantity;
const tax = total * 0.2;

Outputs.total = total;
Outputs.tax = tax;

if (total > 100) {
Outputs.highValue(); // Trigger a signal
}

Defining Ports

The node automatically parses your script to find Inputs.X and Outputs.Y references and creates the corresponding ports. You can also manually define them in the property panel if needed.

Detailed Behavior

  • Async/Await: You can use await inside the script (e.g., await fetch(...)).
  • XGENIA API: The XGENIA object is available for advanced API access (e.g., XGENIA.Model.get(...)).

Troubleshooting

  • Syntax Errors: Check the console for parsing errors.
  • Ports Not Appearing: Try saving the script or clicking off the node to trigger a re-parse.