Learn how to execute JavaScript code within your project using the Run script block in Release0. This guide covers key features, limitations, and examples for effective usage.
The Run script block allows you to execute JavaScript code within your project. Below are its functionalities, limitations, and examples to guide proper usage.
Note: Use
console.log({{My variable}})
instead ofconsole.log("{{My variable}}")
.
setVariable
FunctionIf you want to set a variable value with Javascript, the Set Variable is more appropriate for most cases. However setVariable
function allows you to set values within a Script block.
Important:
- The
setVariable
function is only available in scripts executed on the server.- It will not work if the Execute on client? option is checked.
When scripts are executed on the server, they run in a secure, isolated environment. As a result, some JavaScript functionalities are restricted:
console.log
, setTimeout
, and setInterval
are not available.import
or require
is not supported.window
, document
, and localStorage
are not accessible.The behavior of the fetch
function differs from the native implementation:
response
will always be a string, even if the server returns a JSON object.JSON.parse()
.Note: Avoid using
await response.text()
orawait response.json()
.
If you need access to browser APIs, ensure the Execute on client? option is checked. This allows the script to run in the user’s browser.