Script allows the execution of javascript code extracts (javascript is also known as ECMAScript).

Take a look at the configuration parameters of the component:

  • Code: where the javascript code can be written.

  • Script Timeout: time for the script to expire (in milliseconds).

Messages flow

Input

The Script component can receive former components parameters from the "body" object - in other words, if the component that comes before Script has an output that includes an object called "body", it's possible to access it directly in the Script code.

  • body: object imported to the Script 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 has been successful, "false" if otherwise.

  • output: custom output of the component.

For example, if you want the Script 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"
}

IMPORTANT: due to security matters, it's not possible to execute any function that makes an external call from the Script component, such as fetch() or XMLHttpRequest(). It's also not possible to import Libraries using require. However, the following Libraries are already available to be used:

  • Lodash (global variable to use lodash lib: 'lodash')

  • Moment Timezone (global variable to use moment-timezone: 'moment')

Did this answer your question?