Execute Javascript code
Run JS code with access to variables of current state
This transformation is able to execute Javascript code and return a variable as output. It runs in an isolated environment with the state of the chain passed in as variables that can be accessed via steps
and params
like any other variable. The code must return a value that is then used as the output of the transformation, if no return is provided then there will be no output.
For example, if you wanted to set a default value for a input parameter you would do it as so:
return {
selected_language: params.selected_language ?? 'en'
};
Or if you wanted to check two values from different steps and only return the highest:
let highestValue = steps.first_value.output.answer;
if (highestValue < steps.second_value.output.answer) {
highestValue = steps.second_value.output.answer;
}
return highestValue;
Don't forget to
return
a valueIf the code doesn't
return
any value, it will not have an output.console.log
is ignored.

Screenshot of the JS code transformation in the Notebook
Common errors
- No return is provided in the code
- Execution time exceeds 10 seconds
- An error in the code
Schema
Inputs
Name | Description | Type | Required |
---|---|---|---|
Code | The JavaScript code to execute | String | β |
Outputs
Name | Description | Type |
---|---|---|
Transformed | The returned value from the code | String |
duration | The duration of code execution in milliseconds | Number |
Updated 3 months ago