helpers - UI Builder
-
- UpdatedJan 30, 2025
- 10 minutes to read
- Yokohama
- API reference
The helpers API provides general functionality that is common across page scripts, eliminating the need to write scripts for simple functionality such as opening and closing a modal.
- component property value scripts
- component visibility scripts
- event payload scripts
- UX client script includes
helpers - helpers.modal.close(String modalId)
Closes the specified modal on the current page.
Name | Type | Description |
---|---|---|
modalId | String | Modal component ID of the modal to close. Component IDs are auto generated when a component is dragged and dropped on the UI Builder stage. You can locate the ID on the property page. |
Type | Description |
---|---|
None |
Example
This example shows closing a modal with a component ID that ends with
alert-modal
.
helpers - helpers.modal.open(String modalId, Object options)
Opens the specified modal on the current page.
You can only display one modal at a time within a page. If a modal is currently open, and you call this method, the existing modal is hidden and the new modal appears.
Type | Description |
---|---|
None |
Example
This example shows opening a modal with ca omponent ID that ends with
alert-modal
.
helpers - helpers.navigate.setRouteParams(Object params)
Passes the specified parameters down to other components on the same page.
Use this method in any page component that wants to add a parameter in a URL. You may want
to add a parameter to a URL when another component needs to know the current value of that
parameter when it changes, so it can react to it. For example, use this method to pass the
selectedIndex
of a tab component so it reflected in the URL to give focus
to that tab.
Name | Type | Description |
---|---|---|
params | Object | Key-value pairs of optional parameters to pass to other components. This must be a plain, flat object with only primitive values. Array or object references are ignored and not added to the URL. All specified keys must be part of the optional parameters in the route configuration or they are also ignored. For additional information on optional parameters, see Create a page in UI Builder. |
Type | Description |
---|---|
None |
Example
This code example shows how to append the URL params/selected-tab-index/2
.
Note that the parameter in the actual URL is changed from camel case to snake case, so
selectedTabIndex
becomes selected-tab-index
.
helpers - helpers.navigate.to(String route, Object fields, Object params, Boolean redirect, Boolean passiveNavigation, String targetRoute)
Navigates from one screen to another based on the specified route and field information. URL changes and the respective screen loads are observed.
Type | Description |
---|---|
None |
Example
This example shows how to navigate to a page passing just the route parameter.
Example
This example shows how to navigate to a page passing the route and fields parameters.
Example
This example shows how to navigate to a page passing the route, fields, and params parameters.
helpers - helpers.screen.updateStatus(Object statusObj)
Enables pages to report their status updates, such as title, icon, dirty state, message, and error changes.
Status updates are reported to WorkspaceChrome or AppShell, whichever the outer layer is, and acting as the host.
Name | Type | Description |
---|---|---|
statusObj | Object | Payload to send to the current page to report that the content has been
updated. Valid values:
|
Type | Description |
---|---|
None |
Example
helpers - helpers.snHttp(String url, Object options)
Makes an HTTP request to the ServiceNow instance and returns a promise with the results.
Example
The following example show how to call snHttp() which returns a promise.
Example
The following example show how to call snHttp() using async and await.
Example
The following example show how to set up a POST request.
Example
The following example show how to set up a PUT request.
helpers - helpers.timing.clearInterval(Number timeoutId)
Cancels the execution of the function that was scheduled through a prior setInterval() call.
Name | Type | Description |
---|---|---|
timeoutId | Number | Unique identifier of the scheduled function to clear. This value is returned by the corresponding setInterval() call. |
Type | Description |
---|---|
None |
Example
This example shows using clearInterval() to cancel a timing operation that was previously set using thesetInterval() method. This function could be invoked by a user clicking a Disable Auto-refresh button on a page.
helpers - helpers.timing.clearTimeout(Number timeoutId)
Cancels the execution of the function that was scheduled through a prior setTimeout() call.
Name | Type | Description |
---|---|---|
timeoutId | Number | Unique identifier of the scheduled function to clear. This value is returned by the corresponding setTimeout() call. |
Type | Description |
---|---|
None |
Example
This code example shows how to terminate a timer with the specified timeoutId.
helpers - helpers.timing.setInterval(Function fn, Number delay)
Repeatedly executes the specified function, using the specified delay value as the interval between function calls.
Unlike the native JavaScript setInterval() method, this method does not support passing a code string to evaluate as the first argument. Any additional arguments are passed to the function itself.
Name | Type | Description |
---|---|---|
fn | Function | Function to repeatedly execute. |
delay | Number | Length of the time-interval between each function execution. Unit: Milliseconds |
Type | Description |
---|---|
Number | Unique identifier of the function execution operation. Use this value in the helpers - helpers.timing.clearInterval(Number timeoutId) method if you need to cancel this operation. |
Example
This code example shows how to refresh the timestamp on a page every second. This function could be invoked by a user clicking an Enable Auto-refresh button on a page.
helpers - helpers.timing.setTimeout(Function fn, Number delay)
Executes the specified function, after the specified delay.
Unlike the native JavaScript setTimeout() method, this method does not support passing a code string to evaluate as the first argument. Any additional arguments are passed to the function itself.
Name | Type | Description |
---|---|---|
fn | Function | Function to execute. |
delay | Number | Length of the time to wait before calling the specified function. Unit: Milliseconds |
Type | Description |
---|---|
Number | Unique identifier of the function execution operation. Use this value in the helpers - helpers.timing.clearTimeout(Number timeoutId) method if you need to cancel this operation. |
Example
This code example shows how to set a 20 minute timer. You could associate this function with a button Remind me in 20 minutes.
helpers - helpers.translate(String message, String tokens)
Asynchronously retrieves and translates the specified message based on the current user's session language.
You can use this method with the api - setState(String stateParam, Any value) to bind the translated value to other fields on the page.
async
and
await
. The code examples below show both implementations.Name | Type | Description |
---|---|---|
message | String | Message to translate. |
tokens | String | Optional. Comma-separated list of parameters to use for replacing string
variables. For example: |
Type | Description |
---|---|
String | Translated text string. |
Example
The following example shows how to pass in table field references to embed in the corresponding variables in a string, using a promise.
Example
The following example shows how to use async
and await
in
your function instead of a promise.
On this page
- helpers - helpers.modal.close(String modalId)
- helpers - helpers.modal.open(String modalId, Object options)
- helpers - helpers.navigate.setRouteParams(Object params)
- helpers - helpers.navigate.to(String route, Object fields, Object params, Boolean redirect, Boolean passiveNavigation, String targetRoute)
- helpers - helpers.screen.updateStatus(Object statusObj)
- helpers - helpers.snHttp(String url, Object options)
- helpers - helpers.timing.clearInterval(Number timeoutId)
- helpers - helpers.timing.clearTimeout(Number timeoutId)
- helpers - helpers.timing.setInterval(Function fn, Number delay)
- helpers - helpers.timing.setTimeout(Function fn, Number delay)
- helpers - helpers.translate(String message, String tokens)