Script (JavaScript)
Discover more about the Script (JavaScript) connector and how to use it on the Digibee Integration Platform.
Script (JavaScript) allows the execution of JavaScript code excerpts (JavaScript is also known as ECMAScript).
Parameters
Take a look at the configuration options for the connector. Parameters supported by Double Braces expressions are marked with (DB)
.
Code
Place to insert the JavaScript code.
var currentDate = moment.tz(new Date(), "America/Sao_Paulo"); output = {currentDate: currentDate.format()};
String
Script Timeout
Time for the script to expire (in milliseconds).
10000
Integer
Use Experimental Runtime (Improved Performance)
Enable the experimental runtime for improved performance and consistency. This engine is still in beta.
False
Boolean
Messages flow
Input
The Script (JavaScript) connector can receive former connector parameters from the "body"
object. In other words, if the connector that comes before Script (JavaScript) has an output that includes an object called "body"
, it's possible to access it directly in the Script (JavaScript) code.
body: object imported to the Script (JavaScript) code scope.
For example, if the input is:
{
"body": {
"company": "Digibee"
}
}
Then it will be possible to use the Code field to do something like this:
var x = body.company;
Output
The code executed in the connector can produce an output, as long as it's assigned to the global variable named output.
success:
"true"
if the code execution was successful; otherwise"false"
.output: custom output of the connector.
For example, if you want the Script (JavaScript) connector output to be 'Hello world'
, assign it to the output variable:
output = 'Hello world';
The result after the pipeline execution will be:
{
"success": true,
"output": "Hello world"
}
It's also possible to build a JSON object as an output:
output = { "company": "Digibee" }
The result after the pipeline execution will be:
{
"success": true,
"output": {
"company": "Digibee"
}
}
If an error occurs during the script execution, the following output is displayed after the pipeline execution:
{
"success": false,
"error": "Error message"
}
For security reasons, it's not possible to execute a function that makes an external call from the Script (JavaScript) connector, such as fetch()
or XMLHttpRequest()
. It's also not possible to import libraries with require
.
The following libraries are already available and can be used:
Lodash (global variable to use lodash lib: 'lodash')
Moment Timezone (global variable to use moment-timezone: 'moment')
Usage guidelines
Characteristics of the connector
The engine of the Script (JavaScript) connector has its own infrastructure, which is located outside the pipeline. This means that when running code through this connector, a change of context occurs from the pipeline to its infrastructure.
This infrastructure is shared across the entire platform cluster. For this reason, it’s important to use it consciously and moderately to avoid bottlenecks between pipelines that rely on it.
Recommendations and best practices
The Script (JavaScript) connector is commonly used for data transformation and decision tree implementation, due to its versatility.
However, whenever possible, the Digibee Integration Platform recommends using optimized, pipeline-embedded connectors for data transformation and mapping — such as JOLT, JSLT, JSON Transformer, and JSON Generator. This reduces the risk of processing bottlenecks that can occur with Script (JavaScript).
Use the Script (JavaScript) connector primarily in cases where JavaScript is the only viable option.
Performance and resource usage tips
To ensure stable and efficient execution, follow these best practices and avoid common causes of CPU/memory overload:
Limit input sizes per execution: Avoid processing very large datasets in a single run.
Prefer iterative approaches: Use loops instead of recursion if recursion depth could grow significantly.
Avoid deep cloning in hot paths: Use shallow copies or structural sharing when possible to reduce memory usage.
Use efficient Lodash operations: Prefer
_.forEach
or_.map
with simple iterators; avoid unnecessary_.chain
on large datasets.Validate date/time logic: Handle timezone edge cases carefully; prefer UTC when possible.
Avoid heavy computations or unbounded loops: Infinite/long loops, large nested iterations, or deep recursion without base cases can overload the engine.
Be careful with JSON and regex: Repeated parsing/stringifying of large JSON objects or heavy regex operations on big strings can impact performance.
Monitor object creation: Excessive cloning, merging, or creation of temporary objects in hot loops increases memory usage.
Manage large inputs/outputs: Very large JSON payloads may exceed memory limits or trigger long garbage collection pauses.
Following these recommendations helps reduce the risk of pipeline interruptions, improves performance, and ensures the Script (JavaScript) connector runs efficiently.
Last updated
Was this helpful?