Skip to main content
Version: 2.0-beta.1
JavaScript Node interface

JavaScript node

JavaScript Node

Overview

The JavaScript Node executes custom JavaScript against the pipeline payload and returns the result on a single result output port. It is ideal for ad-hoc transformations, quick calculations, and bridging logic gaps when purpose-built nodes are unavailable. The node injects pipeline context variables, runs the user script inside the Maestro engine, and wraps the return value in a consistent structure for downstream nodes.


Core Functionality

1. Inline JavaScript Execution

  • Author arbitrary ES5/ES6-compatible JavaScript directly inside the node.
  • Access pipeline context variables such as $input, $inputs, $node, and more.
  • Return any JSON-serializable value (objects, arrays, scalars) via a return statement.

2. Context Injection

  • $input: The primary payload (single input or merged data).
  • $inputs['PortOrNode']: Map of inbound packets when synchronizing multiple sources.
  • $node: Metadata describing the current node (id, type, label).
  • Additional globals ($pipeline, $execution) are exposed via the expression service for advanced scenarios.

3. Auto-Wrapped Output

  • Result is emitted through defaultOut under the result field.
  • Downstream nodes receive payloads shaped as { "result": <return value> }.
  • Access outputs via $input.result or drill into nested fields such as $input.result.customer.

4. Standard Settings

  • Shares baseline retry and error handling controls with other nodes.
  • Documentation settings let you annotate the purpose of the script on the pipeline canvas.

Configuration Reference

JavaScript Node parameters

Parameters Tab

Parameters Configuration

JavaScript Node settings

Settings Tab

Settings Configuration

Parameters (Dynamic Data)

FieldTypeDefaultDescription
Javascript Codestring""Required JavaScript snippet that must include a return statement.
Debug ModebooleanfalseEnables verbose execution logging.

Settings (Static Configuration)

FieldTypeDefaultDescription
Retry on FailbooleanfalseRetries execution when infrastructure issues interrupt the script.
On Errorstring"Stop Pipeline""Stop Pipeline" fails the branch, "Continue Execution" forwards an error payload, "Retry Node" replays the script under retry policies.
Notesstring""Document the script’s intent for collaborators.
Display Note in PipelinebooleanfalseShows the note directly on the canvas.

Usage Examples

Example 1: Format Operator Summary

FieldValue
ScriptSee snippet below
NotesBuild operator display name for dashboards.
Display Note in Pipelinetrue
const operator = $input.operator;
return {
id: operator.badgeId,
name: `${operator.firstName} ${operator.lastName}`.trim(),
activeShift: operator.shift
};

The downstream payload exposes the formatted object under $input.result.

Example 2: Calculate Production Yield

FieldValue
ScriptSee snippet below
On ErrorContinue Execution
const produced = Number($input.goodUnits || 0);
const defective = Number($input.scrapUnits || 0);
const total = produced + defective;
if (!total) {
return { yield: 0 };
}
return { yield: Number(((produced / total) * 100).toFixed(2)) };

Even if the script throws, the Continue Execution setting lets the branch proceed for monitoring.

Example 3: Summarize Packaging Batch Metrics

FieldValue
ScriptSee snippet below
On ErrorretryNode
NotesCreate aggregated stats for the current packaging batch.
const cartons = Array.isArray($input.cartons) ? $input.cartons : [];
const totalWeight = cartons.reduce((sum, carton) => sum + (carton.weightKg || 0), 0);
const defectiveCount = cartons.filter(carton => carton.defectFlag === true).length;
return {
batchId: $input.batchId,
cartonCount: cartons.length,
averageWeightKg: cartons.length ? Number((totalWeight / cartons.length).toFixed(2)) : 0,
defectiveCount
};

Use this when a packaging station sends per-carton details and you need a single summary object for downstream reporting.