Skip to main content

Scripts

Scripts are an alternative way of transforming data in Connxio. Instead of uploading code components, you can write JavaScript directly in the Connxio portal. This is a quick and easy way to do small transformations without having to create, test, and upload code components. You have full access to the message content and metadata, and can use standard JavaScript libraries to manipulate the data.

Security

For security reasons, scripts run in a sandboxed environment with limited access to system resources. This means that certain operations, such as file I/O or network access, are not allowed.

Creating a script

To create a script, add a new transformation shape to your integration and select "Script" as the transformation type.

add script shapeadd script shape

You will then be presented with a code editor where you can write your JavaScript code. From here you can make use of the event object which contains the message content and metadata. An example script is provided by default, which you can modify to suit your needs.

/**.
* Handler that will be called during the execution of the script.
* @param {TransformationEvent) event - Contains the file content and metadata about the file.
* @returns {TransformationEvent} Return the modified event.
*/
const execute = (event) => <
// Example modification:
const myobj = JSON. parse(event.content):
myObj newField = "This is a new field added to the JSON object.";
event.content = JSON. stringify (myObj ):
return event;
}
configure script shapeconfigure script shape

When you are done writing your script, click "Done" and save the integration. The script will now be executed whenever a message passes through the transformation shape in your integration.

Testing a script

Included in the script editor is a "Test Script" feature that allows you to test your script with sample data. This is useful for verifying that your script works as expected before deploying it in a live integration. You can provide a test input and metadata, and see the output generated by your script.

test script shapetest script shape

Any errors in your script will be displayed in the errors section, allowing you to quickly identify and fix issues.

You can also make use of console.log() statements in your script to output debug information to the console. This can be helpful for troubleshooting and understanding the flow of your script. The logs are displayed in the "Logs" section of the test results and are ordered in the sequence they were called during script execution. When running the script in a live integration, all logs will be ignored for performance reasons.

Termination

You can terminate a message by throwing an 'Error' from your script. Connxio will check the error message for specific code words to determine how to handle the termination. For any other exceptions, the message will be terminated with an error log level.

You can supply the termination error message with a set of code words to influence the behavior of the termination process. The pipeline is always terminated but the code word controls the logging associated with it. You supply these code words in the following way:

//The code word before the pipe (|) is used to select the action while the text after the pipe is used as the log event message sent via the [logging events functionality](/integrations/logging).
throw new Error("Warning|Integration terminated with warning");

We support the following options on termination:

Code wordAction
Success
WarningThe termination is logged as a warning with the minimum log level.
ErrorThe termination is logged as an error with the none log level.
Loglevel:NoneThe termination is logged with the terminated status but with the none log level instead of the default minimum level.
Loglevel:Never
Default behaviorThe integration is not considered terminated by the user and normal error handling takes over.