Script (JavaScript)

Discover more about the Script (JavaScript) component 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 component. Parameters supported by Double Braces expressions are marked with (DB).

ParameterDescriptionDefault valueData type

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

Messages flow

Input

The Script (JavaScript) component can receive former components parameters from the "body" object. In other words, if the component 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 component 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 component.

For example, if you want the Script (JavaScript) component 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) component, 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 a 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 the pipelines that use it.

The increase in resource capacity of this infrastructure is monitored and managed by the Digibee Integration Platform infrastructure team.

Recommendations and best practices

The Script (JavaScript) connector is commonly used in data transformation and decision tree implementation, due to its versatility.

However, the Digibee Integration Platform recommends using specific connectors for data transformation and data mapping - such as Transformer (JOLT), JSLT, JSON Transformer and JSON Generator (Mock) - whenever possible.

Such connectors are optimized, embedded in the pipeline, and therefore exclusives. This avoids the risk of generating a processing bottleneck, which can happen when using Script (JavaScript).

The use of the Script (JavaScript) connector must be adopted preferably in specific situations, where JavaScript is the only alternative.

Last updated