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
| Data | Description |
|---|---|
| Script | The JavaScript code to execute. |
Actions
| Signal | Description |
|---|---|
| Run | Triggers the script execution. |
Dynamic Inputs
| Data | Description |
|---|---|
| in-* | Inputs defined in the script (e.g., Inputs.myVar) appear as ports here. |
Outputs
Dynamic Outputs
| Data | Description |
|---|---|
| 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
awaitinside the script (e.g.,await fetch(...)). - XGENIA API: The
XGENIAobject 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.