UI Action API - ServiceNow Fluent
The UI Action API defines custom user interface (UI) actions [sys_ui_action], such as buttons, links, and context menu items on forms and lists.
For general information about UI actions, see Create a UI action.
UiAction object
Create a UI action [sys_ui_action] to display on a form.
| Name | Type | Description |
|---|---|---|
| $id | String or Number | Required. A unique ID for the metadata object. When you build the application, this ID is hashed into a unique sys_id. For more information, see ServiceNow Fluent language constructs. Format: |
| table | String | Required. The name of the table on which the UI action is available. By default, the UI action also appears on tables that extend the selected table. For example, Task actions appear on the Incident table. Set the
value to |
| name | String | Required. The text that appears on the button, link, or context menu item. The name must be unique within the table specified. |
| actionName | String | A unique name to use when referencing the UI action in scripts. |
| active | Boolean | Flag that indicates whether the UI action is enabled. Valid values:
Default: true |
| form | Object | Options for how UI actions appear on forms. For more information, see form object. |
| list | Object | Options for how UI actions appear on the list view. For more information, see list object. |
| client | Object | Options to execute the script in the browser. For more information, see client object. |
| workspace | Object | Options for how UI actions function and appear in workspaces. For more information, see workspace object. |
| overrides | Reference or String | The name or variable identifier of another UI action that the UI action overrides. |
| showInsert | Boolean | Flag that indicates whether to show a button on new records before they're inserted. Valid values:
Default: false |
| showUpdate | Boolean | Flag that indicates whether to show a button on existing records. Valid values:
Default: true |
| showQuery | Boolean | Flag that indicates whether the UI action is visible on a list when a filter query is applied. Valid values:
Default: false |
| showMultipleUpdate | Boolean | Flag that indicates whether to show a button when multiple records are selected. Valid values:
Default: false |
| condition | String | A JavaScript conditional statement that specifies the fields and values that must be true for the script to run. 注:
Format:
|
| script | Script | A client-side or server-side script that runs when the UI action is executed. Function names must be unique. This property supports inline JavaScript or a reference to another file in the application that contains a script. Format:
|
| comments | String | Internal notes about the UI action. |
| messages | String | Text strings that the UI action can use as a key to look up a localized message alternative from the Message [sys_ui_message] table. Each message key is on a separate line in the Messages field. The instance looks for a localized message string anytime the UI action makes a getmessage('[message]') call where the message string matches a key in the Messages field. For more information, see Translate a client script message. |
| hint | String | A short description of the UI action that displays as tooltip when hovering over it. |
| order | Number | The order in which the UI action appears. The order applies to buttons from left to right and to menu actions from top to bottom. Default: 100 |
| isolateScript | Boolean | Flag that indicates whether the script runs in strict mode, with access to direct DOM, jQuery, prototype, and the window object turned off. Valid values:
Default: false |
| roles | Array | A list of variable identifiers of Role objects or names of roles required for the UI action to apply. For more information, see Role API - ServiceNow Fluent. |
| includeInViews | Array | A list of names of views in which the UI action is included. |
| excludeFromViews | Array | A list of names of views from which the UI action is excluded. |
| $meta | Object | Metadata for the application metadata. With the installMethod property, you can map the application metadata to an output directory that loads only in specific
circumstances. Valid values for installMethod:
|
import { UiAction } from '@servicenow/sdk/core'
UiAction({
$id: Now.ID['car_info'],
table: 'x_snc_ts_custom_cars',
actionName: 'Car Information',
name: 'View car info',
active: true,
showInsert: true,
showUpdate: true,
hint: 'View car info',
condition: "current.type == 'SUV'",
form: {
showButton: true,
showLink: true,
showContextMenu: false,
style: 'destructive',
},
list: {
showLink: true,
style: 'primary',
showButton: true,
showContextMenu: false,
showListChoice: false,
showBannerButton: true,
showSaveWithFormButton: true,
},
workspace: {
isConfigurableWorkspace: true,
showFormButtonV2: true,
showFormMenuButtonV2: true,
clientScriptV2: `function onClick(g_form) {
}`,
},
script: `current.name = "updated by script";
current.update();`,
roles: ['u_requestor'],
client: {
isClient: true,
isUi11Compatible: true,
isUi16Compatible: true,
},
order: 100,
showQuery: false,
showMultipleUpdate: false,
isolateScript: false,
includeInViews: ['specialView'],
excludeFromViews: [],
})
form object
Configure how a UI action appears on a form.
The form object is a property within the UiAction object.
| Name | Type | Description |
|---|---|---|
| showButton | Boolean | Flag that indicates whether to include a button on a form. Valid values:
Default: false |
| showLink | Boolean | Flag that indicates whether to include a link in the Related Links section of a form. Valid values:
Default: false |
| showContextMenu | Boolean | Flag that indicates whether to include an item in the context menu of a form. Valid values:
Default: false |
| style | String | A style that defines how UI action buttons appear on a form. Valid values:
|
| $meta | Object | Metadata for the application metadata. With the installMethod property, you can map the application metadata to an output directory that loads only in specific
circumstances. Valid values for installMethod:
|
form: {
showButton: true,
showLink: true,
showContextMenu: false,
style: 'destructive',
}
list object
Configure how a UI action appears on the list view.
The list object is a property within the UiAction object.
| Name | Type | Description |
|---|---|---|
| showButton | Boolean | Flag that indicates whether to include a button at the bottom of a list. 注: Buttons at the bottom of a list appear regardless of condition and are evaluated per record on execution. Valid values:
Default: false |
| showLink | Boolean | Flag that indicates whether to include a link in the Related Links section of a list. Valid values:
Default: false |
| showContextMenu | Boolean | Flag that indicates whether to include an item in the context menu of a list. Valid values:
Default: false |
| style | String | A style that defines how UI action buttons appear on the list view. Valid values:
|
| showListChoice | Boolean | Flag that indicates whether to include a choice in the Actions list of a list. 注: Choices in the Actions list appear regardless of condition and are evaluated per record on execution. Valid values:
Default: false |
| showBannerButton | Boolean | Flag that indicates whether to include a button on the banner of a list. 注: Buttons on the banner of a list aren’t intended to support record-specific conditions. Only the first row is considered when the condition is
evaluated to determine whether the button appears for the list. Don't use record-specific conditions, such as current.getValue('state') === 'closed'.Valid values:
Default: false |
| showSaveWithFormButton | Boolean | Flag that indicates whether the form is saved when accessed from a list before executing the UI action button. Valid values:
Default: false |
| $meta | Object | Metadata for the application metadata. With the installMethod property, you can map the application metadata to an output directory that loads only in specific
circumstances. Valid values for installMethod:
|
list: {
showButton: true,
showLink: true,
showContextMenu: false,
style: 'primary',
showListChoice: false,
showBannerButton: true,
showSaveWithFormButton: true,
}
client object
Configure options to execute the UI action script in the browser.
The client object is a property within the UiAction object.
| Name | Type | Description |
|---|---|---|
| isClient | Boolean | Flag that indicates where the UI action script runs. Valid values:
Default: false |
| isUi11Compatible | Boolean | Flag that indicates whether the UI action is supported in the legacy UI 11. Valid values:
Default: false |
| isUi16Compatible | Boolean | Flag that indicates whether the UI action is supported in the Core UI. Valid values:
Default: false |
| onClick | String | The name of the JavaScript function to run when the UI action is executed. The function is defined with the script property. |
| $meta | Object | Metadata for the application metadata. With the installMethod property, you can map the application metadata to an output directory that loads only in specific
circumstances. Valid values for installMethod:
|
client: {
isClient: true,
isUi11Compatible: true,
isUi16Compatible: true,
onClick: 'reopenIncident()'
}
workspace object
Configure how a UI action functions and appears in workspaces.
The workspace object is a property within the UiAction object.
| Name | Type | Description |
|---|---|---|
| isConfigurableWorkspace | Boolean | Flag that indicates the type of workspace in which a UI action applies. Valid values:
Default: false |
| showFormButtonV2 | Boolean | Flag that indicates whether to include a button on forms in a workspace. Valid values:
Default: false |
| showFormMenuButtonV2 | Boolean | Flag that indicates whether to include an item in the More Actions menu in a workspace. Valid values:
Default: false |
| clientScriptV2 | String | A script that runs when the UI action is executed in workspaces. This property supports inline JavaScript or a reference to another file in the application that contains a script. Format:
|
| $meta | Object | Metadata for the application metadata. With the installMethod property, you can map the application metadata to an output directory that loads only in specific
circumstances. Valid values for installMethod:
|
workspace: {
isConfigurableWorkspace: true,
showFormButtonV2: true,
showFormMenuButtonV2: true,
clientScriptV2: `function onClick(g_form) {
}`,
}