Skip to main content
The Run Script element allows you to execute JavaScript code within your project. Below are its functionalities, limitations, and examples to guide proper usage.

Key Features

  • The Script element enables you to execute JavaScript code, but it does not allow you to create custom visual elements.
  • Variables in the script are evaluated, not parsed, so they must be treated as real JavaScript variables.
Note: Use console.log({{My variable}}) instead of console.log("{{My variable}}").

setVariable Function

Purpose

If 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 element.

Example

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.

Server-Side Script Limitations

When scripts are executed on the server, they run in a secure, isolated environment. As a result, some JavaScript functionalities are restricted:

Restricted Functions

  • Global functions like console.log, setTimeout, and setInterval are not available.
  • Importing external libraries using import or require is not supported.
  • Browser APIs like window, document, and localStorage are not accessible.

Fetch Behavior

The behavior of the fetch function differs from the native implementation:
  • The response will always be a string, even if the server returns a JSON object.
  • You need to manually parse the response using JSON.parse().

Examples:

Note: Avoid using await response.text() or await response.json().

Client-Side Script Execution

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.

Examples:

Reload Page

Redirect Based on Variable Value