Skip to main content

The Utils JavaScript Library

JavaScript methods for interacting with apps.

Use the utils JavaScript API methods to perform actions and control behavior.

These methods are not available within transformers or workflows.

JavaScript API methods for this object. You can write JavaScript almost anywhere in Retool and use methods to manipulate data and property values.

utils.changeLocale()

Change the user's locale.

Definition
utils.changeLocale(locale)
Parameters

locale

string

The locale.

Examples

Change the locale to en.

utils.changeLocale('en');

utils.confetti()

Display a confetti animation.

Definition
utils.confetti()
Examples

Display a confetti animation.

utils.confetti();

utils.copyToClipboard()

Copy the specified data to the clipboard.

Definition
utils.copyToClipboard(data)
Parameters

data

string

The data to copy, formatted as a string.

Examples

Copy the value of textInput1.value to the clipboard.

utils.copyToClipboard(textInput1.value);

utils.downloadFile()

Export and download Base64-encoded data.

Definition
utils.downloadFile(options)
Parameters

options

unknown

utils.downloadPage()

Export and download a PDF of the current view for the app in the browser.

Definition
utils.downloadPage(options)
Parameters

options

object
Object Properties

componentsToExclude

string array

A list of component names to exclude.

componentsToInclude

string array

A list of CSS selectors to include.

fullscreen

boolean

Whether to generate a PDF using presentation mode. Defaults to false.

scale

number

The resolution of the generated PDF. Defaults to the value for window.devicePixelRatio.

selectorsToExclude

string array

A list of CSS selectors to exclude.

selectorsToInclude

string array

A list of CSS selectors to include.


utils.exportData()

Exports data as a file in a CSV, TSV, JSON, or Excel format.

Definition
utils.exportData(options)
Parameters

options

unknown

utils.getCurrentPosition()

Retrieves the user's current geographical location, if allowed by the user.

Definition
await utils.getCurrentPosition()
Examples

Get the user's current position.

utils.getCurrentPosition();

utils.getDataByObjectURL()

Converts the contents of a blob: or file:// URL to a Base64-encoded string. Returns a Base64-encoded string.

Definition
utils.getDataByObjectURL(data)
Parameters

data

string

The data to convert.


utils.openApp()

Navigates to another Retool app within the organization.

Definition
utils.openApp(uuid, options)
Parameters

uuid

string

The UUID (Universally Unique Identifier).

options

object
Object Properties

hashParams

object

The value to append as a hash parameter. Only one hash property can be included but it can contain multiple key-value pairs.

newTab

boolean

Whether to open in a new tab. Performs client-side routing if false. Defaults to false.

queryParams

object

Key-value pairs to include as URL query parameters.


utils.openUrl()

Navigates to the specified URL.

Definition
utils.openUrl(url, options)
Parameters

url

string

The URL.

options

object
Object Properties

forceReload

boolean

Whether to prevent client-side routing and force a page reload. Defaults to false.

newTab

boolean

Whether to open in a new tab. Performs client-side routing if false. Defaults to false.


utils.playSound()

Plays an audio file at a specified URL. Supports all browser-compatible audio formats.

Definition
utils.playSound(url)
Parameters

url

string

The URL.


utils.serializePage()

Serializes the current Retool page as a Base64-encoded PDF string. Returns the Base64-encoded string.

Definition
utils.serializePage()

utils.showNotification()

Display an in-app notification.

Definition
utils.showNotification(options)
Parameters

options

unknown