JavaScript in automations

The JavaScript Scripting, or JS Scripting, action within automation is a powerful tool to manipulate data for further steps in Automation. To learn more about using data in automations it is highly recommended to read the Working with data in automations guide.

The JS Scripting action is limited the same way as JavaScript in bindings is limited; it's an asynchronous server-side function. It expects a value to be returned and cannot use external libraries or async calls.

In the JS Scripting action, you can pull all information from previous steps using bindings. They're available in the collapsable "Bindings" block on top and can be accessed using Handlebars notation.

For example, to get from the previous step if the query returned any results, would be to check the success status like this:

if ({{steps.1.success}}) {
    return "Rows have been found";
} else {
    return "Nothing is found";

The value you return in this JavaScript block will be available to any future steps as the value parameter. So the code above was written for Step 2; it would be available to use in other steps by writing:steps.2.value.


Handlebars vs JavaScript Binding

Currently, automations use Handlebars for bindings in the JS Scripting action. This will change to replicate the binding behaviour elsewhere in Budibase. Monitor this ticket on Github to know when this will change.