---
sourceDocument: Xanadu API Reference
sourceDocumentLink: https://servicenow-prod.fluidtopics.net/r/xanadu/api-reference

 Release :

    - xanadu

ft:locale :

    - en-US

ft:publication_title :

    - Xanadu API Reference

ft:clusterId :

    - crapiref

bundleId :

    - crapiref

workflow :

    - Creator


---

# api - UI Builder

# api - UI Builder {#ariaid-title1}

* Release version: Xanadu
* 
* Updated August 1, 2024
* 
* ![](https://www.servicenow.com/docs/portal-asset/ico-clock) 23 minutes to read

The api API provides methods that you can use when developing client
scripts in the UI Builder.  
This API is exposed to client scripts, also known as page scripts. Client scripts are executed in response to something happening on a page, such as:

* User interaction events/actions, such as a button click.
* Lifecycle events, such as a data broker execution started.
These scripts do not have to return anything to the framework and can be written as an asynchronous function.  
This API is also exposed to scripted property values. These scripts are executed whenever the framework-runtime needs to calculate a value, such as:

* Passing to a component property.
* Determining component visibility.
* Emitting an event with a payload.

These scripts cannot be written as an asynchronous function. They also cannot invoke side-effect methods on the api object, such as, api.emit(), api.setState(), and api.data.\<data_resource_id\>.\*().

The api object contains both configuration dependent and configuration independent properties
that you can access within the context of the associated page or component. You cannot
directly modify the properties within this object. Modification can only be made through the
available methods.

## api - api.context.props.\<page_property_name\> {#ariaid-title2}

Page properties can be configured within UI Builder. The
configuration values depend on the context in which the page is used.
{#api-context-props__table_pnc_bkb_n4b__entry__3}

| Name | Type | Description |
|-|-|-|
| \<page_property_name\> | Any | Available values are dependant on the client script implementation. To access these properties, use the following: `api.context.props.<page_property_name>`. For example: `// A record page with property table could be accessed with function isActivityStreamVisible({api}) { return api.context.props.table === 'incident'; } ` Note: These property values are read-only. Mutating nested object values from scripts is not supported. |
[Table 1. Field]

{#api-context-props__table_pnc_bkb_n4b}

## api - api.context.session.\<session_property\> {#ariaid-title3}

Context session properties associated with the current user.
{#api-context-session__table_e24_hkc_n4b__entry__3}

| Name | Type | Description |
|-|-|-|
| isLoggedIn | Boolean | Flag that indicates whether the current user is logged in to the system. Possible values: * true: Current user is logged in to * false: Current user is not logged in. |
| properties.awaEnabled | String | The system property glide.awa.enabled that indicates whether the auto assignment for work items for Advanced Work Assignment (AWA) is enabled for the current user. Possible values: * true: AWA is enabled for the user. * false: AWA is not enabled for the user. For additional information, see [Components installed with Advanced Work Assignment](https://www.servicenow.com/docs/access?context=installed-with-awa&version=xanadu&pubname=xanadu-servicenow-platform&ft:locale=en-US). |
| properties.forgetMe.value | String | The property glide.ui.forgetme that indicates whether to remove the Remember Me check box from the login page to prevent login information from being cached. Possible values: * true: Remove the Remember Me check box. * false: Display the Remember Me check box. For additional information, see [Remove remember me](https://www.servicenow.com/docs/access?context=sc-remove-remember-me&version=xanadu&pubname=xanadu-platform-security&ft:locale=en-US). |
| properties.sessionTimeLeft.value | String Number coerced to string | The system property glide.ui.session_timeleft that determines the mount of time left before the current session times out. Use this property to prompt the user to extent the current session before it times out. Unit: Minutes |
| properties.sessionTimeout.value | String Number coerced to string | The system property glide.ui.session_timeout that determines the initial session time out value. Unit: Minutes - Values greater than 1440 minutes are treated as one day. For additional information, see [Session activity timeout](https://www.servicenow.com/docs/access?context=sc-session-activity-timeout&version=xanadu&pubname=xanadu-platform-security&ft:locale=en-US) |
| properties.trackingEnabled.value | String | The system property glide.uxbuilder.tracking.enabled that indicates whether to enable/disable web analytics library loading and instantiation for UI Builder based applications. Possible values: * true: Enabled for the user. * false: Disabled for the user. |
| user.avatar | String | URL of the current user's avatar. |
| user.dateFormat | String | Default date format. |
| user.domain | String | Domain path for the current user. |
| user.firstName | String | First name of the current user. |
| user.fullName | String | First and last name of the current user. |
| user.initials | String | Initials of the current user. |
| user.language | String | Primary language spoken by the current user. |
| user.preferences | Array of objects | Name-value pairs that describe the user preferences. These user preferences are stored as records in the User Preference \[sys_user_preference\] table, and are updated each time the user changes their settings. For additional information, see [Exploring user administration](https://www.servicenow.com/docs/access?context=exploring-user-administration&version=xanadu&pubname=xanadu-platform-administration&ft:locale=en-US). |
| user.roles | Array | Comma-separated list of roles assigned to the current user. Note: If the user has no roles assigned, this context session property returns null rather than an empty array. |
| user.sys_id | String | Sys_id of the user in the User \[sys_user\] table. |
| user.timeFormat | String | Default time format to use for the user. |
| user.timeZone | String | Time zone of the current user. |
| user.timeZoneOffset | String | Time zone offset of the current user. |
[Table 2. Available session properties]

{#api-context-session__table_e24_hkc_n4b}

## api - api.data.\<data_resource_id\>.lifecycle.lastFetchSucceeded {#ariaid-title4}

Boolean flag that indicates whether the last fetch attempt for the specified data
resource instance finished successfully.
If the value is true, the last fetch attempt for the data resource instance finished
successfully; otherwise, false.
{#api-data-resrc_id-lastFetchSuc__table_svj_czb_n4b__entry__3}{#api-data-resrc_id-lastFetchSuc__data_resource_id-entry-api}

| Name | Type | Description |
|-|-|-|
| data_resource_id | String | Unique identifier of the associated data resource. In most cases, you can use the Form Controller CTRL_RECORD#SAVE_FORM action. If the record page has the Record Page Tabs component, the data resource for this method must be based off of GlideForm (g_form). The available data resource instances are configuration-dependent and defined when you add the data resource to your page in UI Builder. |
[Table 3. Field]

{#api-data-resrc_id-lastFetchSuc__table_svj_czb_n4b}

## api - api.data.\<data_resource_id\>.addErrorMessage(Object payload) {#ariaid-title5}

Displays the specified error message at the top of the current form.
{#api-data-resrc_id-addErrMsg_O__table_pct_ffd_n4b__entry__3}{#api-data-resrc_id-addErrMsg_O__data_resource_id-entry-api}

| Name | Type | Description |
|-|-|-|
| data_resource_id | String | Unique identifier of the associated data resource. In most cases, you can use the Form Controller CTRL_RECORD#SAVE_FORM action. If the record page has the Record Page Tabs component, the data resource for this method must be based off of GlideForm (g_form). The available data resource instances are configuration-dependent and defined when you add the data resource to your page in UI Builder. |
| payload | Object | Object that describes the error message to display. "payload": { "message": "String" } |
| payload.message | String | Error message to display. |
[Table 4. Parameters]

{#api-data-resrc_id-addErrMsg_O__table_pct_ffd_n4b} {#api-data-resrc_id-addErrMsg_O__table_qct_ffd_n4b__entry__2}

| Type | Description |
|-|-|
| None |   |
[Table 5. Returns]

{#api-data-resrc_id-addErrMsg_O__table_qct_ffd_n4b}  
<br />

    api.data.gform.addErrorMessage({message: 'Error message'});

## api -api.data.\<data_resource_id\>.addInfoMessage(Object payload) {#ariaid-title6}

Displays the specified informational message at the top of the current form.
{#api-data-resrc_id-addInfoMsg_O__table_pqr_wdd_n4b__entry__3}{#api-data-resrc_id-addInfoMsg_O__data_resource_id-entry-api}

| Name | Type | Description |
|-|-|-|
| data_resource_id | String | Unique identifier of the associated data resource. In most cases, you can use the Form Controller CTRL_RECORD#SAVE_FORM action. If the record page has the Record Page Tabs component, the data resource for this method must be based off of GlideForm (g_form). The available data resource instances are configuration-dependent and defined when you add the data resource to your page in UI Builder. |
| payload | Object | Object that describes the informational message to display. "payload": { "message": "String" } |
| payload.message | String | Informational message to display. |
[Table 6. Parameters]

{#api-data-resrc_id-addInfoMsg_O__table_pqr_wdd_n4b} {#api-data-resrc_id-addInfoMsg_O__table_qqr_wdd_n4b__entry__2}

| Type | Description |
|-|-|
| None |   |
[Table 7. Returns]

{#api-data-resrc_id-addInfoMsg_O__table_qqr_wdd_n4b}  
<br />

    api.data.gform.addInfoMessage({message: 'Test message'});

## api - api.data.\<data_resource_id\>.addOption(Object payload) {#ariaid-title7}

Adds an option to the specified choice type field.
{#api-data-resrc_id-addOption_O__table_okr_21j_n4b__entry__3}{#api-data-resrc_id-addOption_O__data_resource_id-entry-api}

| Name | Type | Description |
|-|-|-|
| data_resource_id | String | Unique identifier of the associated data resource. In most cases, you can use the Form Controller CTRL_RECORD#SAVE_FORM action. If the record page has the Record Page Tabs component, the data resource for this method must be based off of GlideForm (g_form). The available data resource instances are configuration-dependent and defined when you add the data resource to your page in UI Builder. |
| payload | Object | Object that describes the field value to update. "payload": { "choiceIndex": "String", "choiceLabel": "String", "choiceValue": "String", "fieldName": "String" } |
| payload.choiceIndex | String | Optional. Index into the choice list at which to insert the option. Default: End of the choice list. |
| payload.choiceLabel | String | Label of the option to add to the specified field. |
| payload.choiceValue | String | Value of the option to add to the specified field. |
| payload.fieldName | String | Name of the choice type form field to add the specified option to. |
[Table 8. Parameters]

{#api-data-resrc_id-addOption_O__table_okr_21j_n4b} {#api-data-resrc_id-addOption_O__table_pkr_21j_n4b__entry__2}

| Type | Description |
|-|-|
| None |   |
[Table 9. Returns]

{#api-data-resrc_id-addOption_O__table_pkr_21j_n4b}  
<br />

    api.data.gform.addOption({fieldName: 'priority', choiceLabel: 'Extremely High', choiceValue: '10'});

## api - api.data.\<data_resource_id\>.addWarningMessage(Object payload) {#ariaid-title8}

Displays the specified warning message at the top of the current form.
{#api-data-resrc_id-addWarnMsg_O__table_mgf_v2d_n4b__entry__3}{#api-data-resrc_id-addWarnMsg_O__data_resource_id-entry-api}

| Name | Type | Description |
|-|-|-|
| data_resource_id | String | Unique identifier of the associated data resource. In most cases, you can use the Form Controller CTRL_RECORD#SAVE_FORM action. If the record page has the Record Page Tabs component, the data resource for this method must be based off of GlideForm (g_form). The available data resource instances are configuration-dependent and defined when you add the data resource to your page in UI Builder. |
| payload | Object | Object that describes the warning message to display. "payload": { "message": "String" } |
| payload.message | String | Warning message to display. |
[Table 10. Parameters]

{#api-data-resrc_id-addWarnMsg_O__table_mgf_v2d_n4b} {#api-data-resrc_id-addWarnMsg_O__table_ngf_v2d_n4b__entry__2}

| Type | Description |
|-|-|
| None |   |
[Table 11. Returns]

{#api-data-resrc_id-addWarnMsg_O__table_ngf_v2d_n4b}  
<br />

    api.data.gform.addWarningMessage({message: 'Test message'});

## api - api.data.\<data_resource_id\>.clearMessage() {#ariaid-title9}

Removes all informational and error messages from the top of the current form.
{#api-data-resrc_id-clearMsg__table_g4t_qfd_n4b__entry__3}{#api-data-resrc_id-clearMsg__data_resource_id-entry-api}

| Name | Type | Description |
|-|-|-|
| data_resource_id | String | Unique identifier of the associated data resource. In most cases, you can use the Form Controller CTRL_RECORD#SAVE_FORM action. If the record page has the Record Page Tabs component, the data resource for this method must be based off of GlideForm (g_form). The available data resource instances are configuration-dependent and defined when you add the data resource to your page in UI Builder. |
[Table 12. Parameters]

{#api-data-resrc_id-clearMsg__table_g4t_qfd_n4b} {#api-data-resrc_id-clearMsg__table_h4t_qfd_n4b__entry__2}

| Type | Description |
|-|-|
| None |   |
[Table 13. Returns]

{#api-data-resrc_id-clearMsg__table_h4t_qfd_n4b}  
<br />

    api.data.gform.clearMessage();

## api - api.data.\<data_resource_id\>.clearOptions(Object payload) {#ariaid-title10}

Clears all options from the specified choice type field.
{#api-data-resrc_id-clearOptions_O__table_c3x_4dj_n4b__entry__3}{#api-data-resrc_id-clearOptions_O__data_resource_id-entry-api}

| Name | Type | Description |
|-|-|-|
| data_resource_id | String | Unique identifier of the associated data resource. In most cases, you can use the Form Controller CTRL_RECORD#SAVE_FORM action. If the record page has the Record Page Tabs component, the data resource for this method must be based off of GlideForm (g_form). The available data resource instances are configuration-dependent and defined when you add the data resource to your page in UI Builder. |
| payload | Object | Object that describes the choice type field whose options are to be cleared. "payload": { "fieldName": "String" } |
| payload.fieldName | String | Name of the choice type field whose options are to be cleared. |
[Table 14. Parameters]

{#api-data-resrc_id-clearOptions_O__table_c3x_4dj_n4b} {#api-data-resrc_id-clearOptions_O__table_d3x_4dj_n4b__entry__2}

| Type | Description |
|-|-|
| None |   |
[Table 15. Returns]

{#api-data-resrc_id-clearOptions_O__table_d3x_4dj_n4b}  
<br />

    api.data.gform.clearOptions({fieldName: 'priority'});

## api - api.data.\<data_resource_id\>.executeUiAction(Object payload) {#ariaid-title11}

Executes the specified UI action.
{#api-data-resrc_id-execUIAct_O__table_l41_s2j_n4b__entry__3}{#api-data-resrc_id-execUIAct_O__data_resource_id-entry-api}

| Name | Type | Description |
|-|-|-|
| data_resource_id | String | Unique identifier of the associated data resource. In most cases, you can use the Form Controller CTRL_RECORD#SAVE_FORM action. If the record page has the Record Page Tabs component, the data resource for this method must be based off of GlideForm (g_form). The available data resource instances are configuration-dependent and defined when you add the data resource to your page in UI Builder. |
| payload | Object | Object that describes the UI action to execute. "payload": { "actionSysId": "String" } |
| payload.actionSysId | String | Sys_id of the UI action to execute. Located in the UI Action \[sys_ui_action\] table. |
[Table 16. Parameters]

{#api-data-resrc_id-execUIAct_O__table_l41_s2j_n4b} {#api-data-resrc_id-execUIAct_O__table_m41_s2j_n4b__entry__2}

| Type | Description |
|-|-|
| None |   |
[Table 17. Returns]

{#api-data-resrc_id-execUIAct_O__table_m41_s2j_n4b}  
<br />

    api.data.gform.executeUiAction({actionSysId: '60615ff90f730010ac7de6f8c4767e9a'});

## api - api.data.\<data_resource_id\>.execute(Object inputValues) {#ariaid-title12}

Triggers an execute operation on the specified data resource.
This method is only available if the data resource is one of the following types:

* Composite
* GraphQL
* REST
* Scriptlet
* Transform
{#api-data-resrc_id-execute__ul_slc_xq1_54b}  
Note:  
This method is only exposed if the mutates_server_data field is set to <kbd class="ph userinput">true</kbd> on the corresponding data resource (sys_ux_data_broker_\* table) record. It is accessible under api.data.\<data_resource_Id\>.refresh(). {#api-data-resrc_id-execute__table_m52_lyc_n4b__entry__3}{#api-data-resrc_id-execute__data_resource_id_non_gform-entry-api}

| Name | Type | Description |
|-|-|-|
| data_resource_id | String | Unique identifier of the associated data resource. The available data resource instances are configuration-dependent and defined when you add the data resource to your page in UI Builder. |
| inputValues | Object | Object to pass to the specified data resource. This object must conform to the data resource's input parameters. |
[Table 18. Parameters]

{#api-data-resrc_id-execute__table_m52_lyc_n4b} {#api-data-resrc_id-execute__table_n52_lyc_n4b__entry__2}

| Type | Description |
|-|-|
| None |   |
[Table 19. Returns]

{#api-data-resrc_id-execute__table_n52_lyc_n4b}  
This code example shows a page script that is invoked when the
Submit button on the page is clicked. The page is configured wit a
Server Data Resource tat creates a new record.

    function handler({api}) {
      if (api.state.movieYear === 2020) {
        // The data resource used in this case specifies two input parameters: name and year
        api.data.create_movie_record.execute({
          name: api.state.movieName,
          year: api.state.movieYear
        });
      }
    }

## api - api.data.\<data_resource_id\>.hideFieldMessage(Object payload) {#ariaid-title13}

Hides the oldest message next to the specified field or clears all messages associated
with the field.
{#api-data-resrc_id-hideFldMsg__table_jl3_b33_n4b__entry__3}{#api-data-resrc_id-hideFldMsg__data_resource_id-entry-api}

| Name | Type | Description |
|-|-|-|
| data_resource_id | String | Unique identifier of the associated data resource. In most cases, you can use the Form Controller CTRL_RECORD#SAVE_FORM action. If the record page has the Record Page Tabs component, the data resource for this method must be based off of GlideForm (g_form). The available data resource instances are configuration-dependent and defined when you add the data resource to your page in UI Builder. |
| payload | Object | Object that describes the field message to hide. "payload": { "clearAll": Boolean, "fieldName": "String" } |
| payload.clearAll | Boolean | Optional. Flag that indicates whether to clear all messages associated with the specified form field. Valid values: * true: Clear all messages associated with the specified field. * false: Do not clear all messages associated with the specified field. Default: false |
| payload.fieldName | String | Name of the form field for which to hide the oldest message or clear all associated messages. |
[Table 20. Parameters]

{#api-data-resrc_id-hideFldMsg__table_jl3_b33_n4b} {#api-data-resrc_id-hideFldMsg__table_kl3_b33_n4b__entry__2}

| Type | Description |
|-|-|
| None |   |
[Table 21. Returns]

{#api-data-resrc_id-hideFldMsg__table_kl3_b33_n4b}  
<br />

    api.data.gform.hideFieldMessage({fieldName: 'short_description'});

## api - api.data.\<data_resource_id\>.hideRelatedList(Object payload) {#ariaid-title14}

Hides the specified related list on the current form.
{#api-data-resrc_id-hideRelList_O__table_yxg_jq3_n4b__entry__3}{#api-data-resrc_id-hideRelList_O__data_resource_id-entry-api}

| Name | Type | Description |
|-|-|-|
| data_resource_id | String | Unique identifier of the associated data resource. In most cases, you can use the Form Controller CTRL_RECORD#SAVE_FORM action. If the record page has the Record Page Tabs component, the data resource for this method must be based off of GlideForm (g_form). The available data resource instances are configuration-dependent and defined when you add the data resource to your page in UI Builder. |
| payload | Object | Object that describes the related list to hide. "payload": { "listTableName ": "String" } |
| payload.listTableName | String | Name of the related list to hide. Located in the Related List \[sys_ui_related_list\] table. If the list to hide is through a relationship, provide the sys_id of the list instead of the name. |
[Table 22. Parameters]

{#api-data-resrc_id-hideRelList_O__table_yxg_jq3_n4b} {#api-data-resrc_id-hideRelList_O__table_zxg_jq3_n4b__entry__2}

| Type | Description |
|-|-|
| None |   |
[Table 23. Returns]

{#api-data-resrc_id-hideRelList_O__table_zxg_jq3_n4b}  
<br />

    api.data.gform.hideRelatedList({listTableName:'incident.parent_incident'});

## api - api.data.\<data_resource_id\>.hideRelatedLists() {#ariaid-title15}

Hides all related lists on the current form.
{#api-data-resrc_id-hideRelLists__table_cy4_cm3_n4b__entry__3}{#api-data-resrc_id-hideRelLists__data_resource_id-entry-api}

| Name | Type | Description |
|-|-|-|
| data_resource_id | String | Unique identifier of the associated data resource. In most cases, you can use the Form Controller CTRL_RECORD#SAVE_FORM action. If the record page has the Record Page Tabs component, the data resource for this method must be based off of GlideForm (g_form). The available data resource instances are configuration-dependent and defined when you add the data resource to your page in UI Builder. |
[Table 24. Parameters]

{#api-data-resrc_id-hideRelLists__table_cy4_cm3_n4b} {#api-data-resrc_id-hideRelLists__table_dy4_cm3_n4b__entry__2}

| Type | Description |
|-|-|
| None |   |
[Table 25. Returns]

{#api-data-resrc_id-hideRelLists__table_dy4_cm3_n4b}  
<br />

    api.data.gform.hideRelatedLists();

## api - api.data.\<data_resource_id\>.refresh() {#ariaid-title16}

Triggers a refresh operation for the specified non-mutating data resource
instance.
Call this method if the underlying data being fetched by the data resource changes. A data
resource is considered non-mutating if the mutates_server_data field on
the record is set to false.

This method is asynchronous and emits an internal event to trigger the refresh of the
specified data resource instance. The UI Builder allows you to trigger
client scripts in response to data resource lifecycle events, such as DATA_FETCH_SUCCEEDED
and DATA_FETCH_FAILED. For additional information on these events, see [Event mapping](https://www.servicenow.com/docs/access?context=event-mapping&version=xanadu&pubname=xanadu-application-development&ft:locale=en-US).  
This method is only available if the data resource is one of the following types:

* Composite
* GraphQL
* REST
* Scriptlet
* Transform
{#api-data-resrc_id-refresh__ul_slc_xq1_54b}  
Note:  
This method is only exposed if the mutates_server_data field is set to <kbd class="ph userinput">false</kbd> on the corresponding data resource (sys_ux_data_broker_\* table) record. {#api-data-resrc_id-refresh__table_jrk_spc_n4b__entry__3}{#api-data-resrc_id-refresh__data_resource_id_non_gform-entry-api}

| Name | Type | Description |
|-|-|-|
| data_resource_id | String | Unique identifier of the associated data resource. The available data resource instances are configuration-dependent and defined when you add the data resource to your page in UI Builder. |
[Table 26. Parameters]

{#api-data-resrc_id-refresh__table_jrk_spc_n4b} {#api-data-resrc_id-refresh__table_krk_spc_n4b__entry__2}

| Type | Description |
|-|-|
| None |   |
[Table 27. Returns]

{#api-data-resrc_id-refresh__table_krk_spc_n4b}  
This code example shows a page script that is invoked when a dropdown item is selected in a
page. The page is configured with two Server Data Resources that query problem and incident
tables.

    function handler({api, event}) {
      const value = event.payload.value[0];
      if (value === 'problem')
        api.data.problem_list_1.refresh();
      else if(value === 'incident')
        api.data.incident_list_1.refresh();
    }

## api - api.data.\<data_resource_id\>.reload() {#ariaid-title17}

Reloads the current form using the same table and sys_id.
{#api-data-resrc_id-reload__table_cwc_kw3_n4b__entry__3}{#api-data-resrc_id-reload__data_resource_id-entry-api}

| Name | Type | Description |
|-|-|-|
| data_resource_id | String | Unique identifier of the associated data resource. In most cases, you can use the Form Controller CTRL_RECORD#SAVE_FORM action. If the record page has the Record Page Tabs component, the data resource for this method must be based off of GlideForm (g_form). The available data resource instances are configuration-dependent and defined when you add the data resource to your page in UI Builder. |
[Table 28. Parameters]

{#api-data-resrc_id-reload__table_cwc_kw3_n4b} {#api-data-resrc_id-reload__table_dwc_kw3_n4b__entry__2}

| Type | Description |
|-|-|
| None |   |
[Table 29. Returns]

{#api-data-resrc_id-reload__table_dwc_kw3_n4b}  
<br />

    api.data.gform.reload();

## api - api.data.\<data_resource_id\>.removeOption(Object payload) {#ariaid-title18}

Removes an option from the specified choice type field.
{#api-data-resrc_id-removeOption_O__table_gky_wcj_n4b__entry__3}{#api-data-resrc_id-removeOption_O__data_resource_id-entry-api}

| Name | Type | Description |
|-|-|-|
| data_resource_id | String | Unique identifier of the associated data resource. In most cases, you can use the Form Controller CTRL_RECORD#SAVE_FORM action. If the record page has the Record Page Tabs component, the data resource for this method must be based off of GlideForm (g_form). The available data resource instances are configuration-dependent and defined when you add the data resource to your page in UI Builder. |
| payload | Object | Object that describes the choice type field to update. "payload": { "choiceValue": "String", "fieldName": "String" } |
| payload.choiceValue | String | Value of the option to remove from the specified choice type field. |
| payload.fieldName | String | Name of the choice type form field from which to remove the specified value. |
[Table 30. Parameters]

{#api-data-resrc_id-removeOption_O__table_gky_wcj_n4b} {#api-data-resrc_id-removeOption_O__table_hky_wcj_n4b__entry__2}

| Type | Description |
|-|-|
| None |   |
[Table 31. Returns]

{#api-data-resrc_id-removeOption_O__table_hky_wcj_n4b}  
<br />

    api.data.gform.removeOption({fieldName: 'priority', choiceValue: '1'});

## api - api.data.\<data_resource_id\>.save() {#ariaid-title19}

Triggers form submission using the Save UI action.
{#api-data-resrc_id-save__table_fn1_vw3_n4b__entry__3}{#api-data-resrc_id-save__data_resource_id-entry-api}

| Name | Type | Description |
|-|-|-|
| data_resource_id | String | Unique identifier of the associated data resource. In most cases, you can use the Form Controller CTRL_RECORD#SAVE_FORM action. If the record page has the Record Page Tabs component, the data resource for this method must be based off of GlideForm (g_form). The available data resource instances are configuration-dependent and defined when you add the data resource to your page in UI Builder. |
[Table 32. Parameters]

{#api-data-resrc_id-save__table_fn1_vw3_n4b} {#api-data-resrc_id-save__table_gn1_vw3_n4b__entry__2}

| Type | Description |
|-|-|
| None |   |
[Table 33. Returns]

{#api-data-resrc_id-save__table_gn1_vw3_n4b}  
<br />

    api.data.gform.save();

## api - api.data.\<data_resource_id\>.setMandatory(Object payload) {#ariaid-title20}

Sets whether the specified form field is mandatory.
{#api-data-resrc_id-setMan_O__table_yws_2v3_n4b__entry__3}{#api-data-resrc_id-setMan_O__data_resource_id-entry-api}

| Name | Type | Description |
|-|-|-|
| data_resource_id | String | Unique identifier of the associated data resource. In most cases, you can use the Form Controller CTRL_RECORD#SAVE_FORM action. If the record page has the Record Page Tabs component, the data resource for this method must be based off of GlideForm (g_form). The available data resource instances are configuration-dependent and defined when you add the data resource to your page in UI Builder. |
| payload | Object | Object that describes the field whose mandatory information to update. "payload": { "fieldName": "String", "mandatory": Boolean } |
| payload.fieldName | String | Name of the form field whose mandatory value is to be set. |
| payload.mandatory | Boolean | Flag that indicates the specified form field is mandatory, meaning the form cannot be saved without this field containing a valid value. Valid values: * true: Field is mandatory. * false: Field is optional. |
[Table 34. Parameters]

{#api-data-resrc_id-setMan_O__table_yws_2v3_n4b} {#api-data-resrc_id-setMan_O__table_zws_2v3_n4b__entry__2}

| Type | Description |
|-|-|
| None |   |
[Table 35. Returns]

{#api-data-resrc_id-setMan_O__table_zws_2v3_n4b}  
<br />

    api.data.gform.setMandatory({fieldName: 'short_description', mandatory: false});

## api - api.data.\<data_resource_id\>.setReadOnly(Object payload) {#ariaid-title21}

Sets the read/write capabilities of the specified form field.
{#api-data-resrc_id-setReadOnly_O__table_d13_ps3_n4b__entry__3}{#api-data-resrc_id-setReadOnly_O__data_resource_id-entry-api}

| Name | Type | Description |
|-|-|-|
| data_resource_id | String | Unique identifier of the associated data resource. In most cases, you can use the Form Controller CTRL_RECORD#SAVE_FORM action. If the record page has the Record Page Tabs component, the data resource for this method must be based off of GlideForm (g_form). The available data resource instances are configuration-dependent and defined when you add the data resource to your page in UI Builder. |
| payload | Object | Object that describes the field whose readability information to update. "payload": { "fieldName": "String", "readonly": Boolean } |
| payload.fieldName | String | Name of the form field whose readability is to be set. |
| payload.readonly | Boolean | Flag that indicates the read/write capabilities of the specified form field. Valid values: * true: Field is read only. * false: Field is read/write. |
[Table 36. Parameters]

{#api-data-resrc_id-setReadOnly_O__table_d13_ps3_n4b} {#api-data-resrc_id-setReadOnly_O__table_e13_ps3_n4b__entry__2}

| Type | Description |
|-|-|
| None |   |
[Table 37. Returns]

{#api-data-resrc_id-setReadOnly_O__table_e13_ps3_n4b}  
<br />

    api.data.gform.setReadOnly({fieldName: 'short_description', readonly: false});

## api -api.data.\<data_resource_id\>.setValue(Object payload) {#ariaid-title22}

Updates a specified GlideForm field with the specified value. Optionally, you can also
update the display value with the same specified value.
Only the value on the form is updated. The value is not saved in the database.
{#api-data-resrc_id-setValue_O__table_tyh_31d_n4b__entry__3}{#api-data-resrc_id-setValue_O__data_resource_id-entry-api}

| Name | Type | Description |
|-|-|-|
| data_resource_id | String | Unique identifier of the associated data resource. In most cases, you can use the Form Controller CTRL_RECORD#SAVE_FORM action. If the record page has the Record Page Tabs component, the data resource for this method must be based off of GlideForm (g_form). The available data resource instances are configuration-dependent and defined when you add the data resource to your page in UI Builder. |
| payload | Object | Object that describes the field whose value to update. "payload": { "displayValue": "String", "fieldName": "String", "value": "String" } |
| payload.displayValue | String | Optional. Name of the display value to update. If left blank, the display value is not modified. |
| payload.fieldName | String | Name of the form field to update. |
| payload.value | String | Value to update the field with. |
[Table 38. Parameters]

{#api-data-resrc_id-setValue_O__table_tyh_31d_n4b} {#api-data-resrc_id-setValue_O__table_uyh_31d_n4b__entry__2}

| Type | Description |
|-|-|
| None |   |
[Table 39. Returns]

{#api-data-resrc_id-setValue_O__table_uyh_31d_n4b}  
<br />

    api.data.gform.setValue({fieldName: 'short_description', value: 'short description'});

## api - api.data.\<data_resource_id\>.setVisible(Object payload) {#ariaid-title23}

Sets the visibility of the specified form field.
{#api-data-resrc_id-setVisible_O__table_j5k_gr3_n4b__entry__3}{#api-data-resrc_id-setVisible_O__data_resource_id-entry-api}

| Name | Type | Description |
|-|-|-|
| data_resource_id | String | Unique identifier of the associated data resource. In most cases, you can use the Form Controller CTRL_RECORD#SAVE_FORM action. If the record page has the Record Page Tabs component, the data resource for this method must be based off of GlideForm (g_form). The available data resource instances are configuration-dependent and defined when you add the data resource to your page in UI Builder. |
| payload | Object | Object that describes the field on which to set visibility. "payload": { "fieldName": "String", "visibility": Boolean } |
| payload.fieldName | String | Name of the form field whose visibility is to be set. |
| payload.visibility | Boolean | Flag that indicates whether the associated field is visible on the current form. Valid values: * true: Field will display on the form. * false: Field will not display on the form. |
[Table 40. Parameters]

{#api-data-resrc_id-setVisible_O__table_j5k_gr3_n4b} {#api-data-resrc_id-setVisible_O__table_k5k_gr3_n4b__entry__2}

| Type | Description |
|-|-|
| None |   |
[Table 41. Returns]

{#api-data-resrc_id-setVisible_O__table_k5k_gr3_n4b}  
<br />

    api.data.gform.setVisible({fieldName: 'short_description', visibility: false});

## api - api.data.\<data_resource_id\>.showFieldMessage(Object payload) {#ariaid-title24}

Displays the specified message next to the specified field.
{#api-data-resrc_id-showFldMsg_O__table_o35_xgd_n4b__entry__3}{#api-data-resrc_id-showFldMsg_O__data_resource_id-entry-api}

| Name | Type | Description |
|-|-|-|
| data_resource_id | String | Unique identifier of the associated data resource. In most cases, you can use the Form Controller CTRL_RECORD#SAVE_FORM action. If the record page has the Record Page Tabs component, the data resource for this method must be based off of GlideForm (g_form). The available data resource instances are configuration-dependent and defined when you add the data resource to your page in UI Builder. |
| payload | Object | Object that describes the field message to display. "payload": { "fieldName": "String", "message": "String", "type": "String" |
| payload.fieldName | String | Name of the field next to which the message should appear. |
| payload.message | String | Message to display. |
| payload.type | String | Optional. Type of message to display. Valid values: * error * info * warning Default: info |
[Table 42. Parameters]

{#api-data-resrc_id-showFldMsg_O__table_o35_xgd_n4b} {#api-data-resrc_id-showFldMsg_O__table_p35_xgd_n4b__entry__2}

| Type | Description |
|-|-|
| None |   |
[Table 43. Returns]

{#api-data-resrc_id-showFldMsg_O__table_p35_xgd_n4b}  
<br />

    api.data.gform.showFieldMessage({fieldName: 'short_description', message: 'Error message', type: 'error'});

## api - api.data.\<data_resource_id\>.showRelatedList(Object payload) {#ariaid-title25}

Displays the specified related list on the current form.
{#api-data-resrc_id-showRelList_O__table_xc2_tn3_n4b__entry__3}{#api-data-resrc_id-showRelList_O__data_resource_id-entry-api}

| Name | Type | Description |
|-|-|-|
| data_resource_id | String | Unique identifier of the associated data resource. In most cases, you can use the Form Controller CTRL_RECORD#SAVE_FORM action. If the record page has the Record Page Tabs component, the data resource for this method must be based off of GlideForm (g_form). The available data resource instances are configuration-dependent and defined when you add the data resource to your page in UI Builder. |
| payload | Object | Object that describes the related list to display. "payload": { "listTableName ": "String" } |
| payload.listTableName | String | Name of the related list to display. Located in the Related List \[sys_ui_related_list\] table. If the list to display is through a relationship, provide the sys_id of the list instead of the name. |
[Table 44. Parameters]

{#api-data-resrc_id-showRelList_O__table_xc2_tn3_n4b} {#api-data-resrc_id-showRelList_O__table_yc2_tn3_n4b__entry__2}

| Type | Description |
|-|-|
| None |   |
[Table 45. Returns]

{#api-data-resrc_id-showRelList_O__table_yc2_tn3_n4b}  
<br />

    api.data.gform.showRelatedList({listTableName:'incident.parent_incident'});

## api - api.data.\<data_resource_id\>.showRelatedLists() {#ariaid-title26}

Displays all related lists associated with the current form.
{#api-data-resrc_id-showRelLists__table_wzd_sl3_n4b__entry__3}{#api-data-resrc_id-showRelLists__data_resource_id-entry-api}

| Name | Type | Description |
|-|-|-|
| data_resource_id | String | Unique identifier of the associated data resource. In most cases, you can use the Form Controller CTRL_RECORD#SAVE_FORM action. If the record page has the Record Page Tabs component, the data resource for this method must be based off of GlideForm (g_form). The available data resource instances are configuration-dependent and defined when you add the data resource to your page in UI Builder. |
[Table 46. Parameters]

{#api-data-resrc_id-showRelLists__table_wzd_sl3_n4b} {#api-data-resrc_id-showRelLists__table_xzd_sl3_n4b__entry__2}

| Type | Description |
|-|-|
| None |   |
[Table 47. Returns]

{#api-data-resrc_id-showRelLists__table_xzd_sl3_n4b}  
<br />

    api.data.gform.showRelatedLists();

## api - api.data.\<data_resource_id\>.submit() {#ariaid-title27}

Triggers form submission using the specified UI action.
{#api-data-resrc_id-submit_O__table_zc1_hx3_n4b__entry__3}{#api-data-resrc_id-submit_O__data_resource_id-entry-api}

| Name | Type | Description |
|-|-|-|
| data_resource_id | String | Unique identifier of the associated data resource. In most cases, you can use the Form Controller CTRL_RECORD#SAVE_FORM action. If the record page has the Record Page Tabs component, the data resource for this method must be based off of GlideForm (g_form). The available data resource instances are configuration-dependent and defined when you add the data resource to your page in UI Builder. |
| payload | Object | Object that describes the UI action to use to submit the current form. "payload": { "submitActionName": "String" } |
| payload.submitActionName | String | Name of the UI action to execute to submit the current form. |
[Table 48. Parameters]

{#api-data-resrc_id-submit_O__table_zc1_hx3_n4b} {#api-data-resrc_id-submit_O__table_ad1_hx3_n4b__entry__2}

| Type | Description |
|-|-|
| None |   |
[Table 49. Returns]

{#api-data-resrc_id-submit_O__table_ad1_hx3_n4b}  
<br />

    api.data.gform.submit({submitActionName:'sysverb_ws_save'});

## api - api.emit(String eventName, Object payload) {#ariaid-title28}

Emits an event with the specified name and payload.
The event name being emitted must be part of the associated page definition's dispatched
events list, which is stored in the UX Macroponent Definition \[sys_ux_macroponent\] table.
Any api.emit call that dispatches events not declared in this table are
ignored.

For additional information on events, see [Work with events](https://www.servicenow.com/docs/access?context=work-events&version=xanadu&pubname=xanadu-application-development&ft:locale=en-US).
{#api-emit_S_O__table_yyz_njj_n4b__entry__3}

| Name | Type | Description |
|-|-|-|
| eventName | String | Name of the event to emit. This name should follow the UI Framework action naming guidelines: * Should be upper snake case, such as ITEM_CHANGED. All letters in upper case and all spaces replaced with underscores. * Should be past tense, such as BUTTON_CLICKED or USER_SELECTED. {#api-emit_S_O__ul_xgx_cgk_n4b} For additional information on these action naming guidelines, see <https://developer.servicenow.com/dev.do#!/reference/now-experience/sandiego/ui-framework/main-concepts/dispatching-actions>. |
| payload | Object | Optional. Object that contains the data to send with the emitted event. This object is free-form and can contain whatever data is necessary by the entity receiving the data. Note: Payloads of primitive type work, but could result in inconsistent behavior. |
[Table 50. Parameters]

{#api-emit_S_O__table_yyz_njj_n4b} {#api-emit_S_O__table_zyz_njj_n4b__entry__2}

| Type | Description |
|-|-|
| None |   |
[Table 51. Returns]

{#api-emit_S_O__table_zyz_njj_n4b}  
The following code example shows emitting an event called
NOW_UXF_PAGE#ADD_NOTIFICATIONS with an associated
items payload.

    function handler({api}) { 
      api.emit('NOW_UXF_PAGE#ADD_NOTIFICATIONS', { 
        items: [
          { 
            id: 'alert1', 
            status: 'positive', 
            icon: 'check-circle-outline', 
            content: 'Here is some information!', 
            textLinkProps: { 
              label: 'More info',
              href: 'https://www.servicenow.com' 
            }, 
          action: {type: 'acknowledge'} 
          } 
        ] 
      }); 
    } 

## api - setState(String stateParam, Any value) {#ariaid-title29}

Sets the value of the specified client state parameter.
Use client state parameters to maintain a shared state on a page.
The shared state can then be passed as values to properties of components used on the page.
You can also access and update client states in multiple page scripts. A common use case is
to keep track of values input by users in multiple form controls on a page. When the form is
submitted, a client script could then use all of the values stored in client state
parameters to create a new record with a data broker. A page can have one or more client
state parameters, which you can declare for a page through the UI Builder. You can then bind
a client state parameter to one or more components to share or act on the client state
parameter.

api.setState() calls are executed
asynchronously and do not necessarily update the UI immediately. If the value to set depends
on the currentValue of the client state parameter, or any of the
properties provided in the api object, you should use this variant of the
api.setState() method to avoid using outdated values.
{#api-setState_S_A__table_lgw_35q_n4b__entry__3}{#api-setState_S_A__stateParm-entry-api}

| Name | Type | Description |
|-|-|-|
| stateParm | String | Name of the client state parameter to update. This name must be declared in the client state parameters of the associated page. For additional information on declaring client state parameters, see [Work with client state parameters](https://www.servicenow.com/docs/access?context=state-parameters&version=xanadu&pubname=xanadu-application-development&ft:locale=en-US). |
| value | Any - Must be the same as the client state parameter declaration. | Value to set the specified client state parameter to. |
[Table 52. Parameters]

{#api-setState_S_A__table_lgw_35q_n4b} {#api-setState_S_A__table_mgw_35q_n4b__entry__2}

| Type | Description |
|-|-|
| None |   |
[Table 53. Returns]

{#api-setState_S_A__table_mgw_35q_n4b}  
This example shows a script that could be executed to update the email client state
parameter when an input value is set on a now-input component.

    function handler({api, event}) {
        api.setState('email', event.payload.value);
    }

## api - setState(String stateParam, Function callbackFn) {#ariaid-title30}

Sets the value of the specified client state parameter to the value returned by the
specified callback function.
The callback function is invoked with an object that has two properties:
currentValue and api. The function should never
mutate the currentValue property or the api object
directly.

Use client state parameters to maintain a shared state on a page.
The shared state can then be passed as values to properties of components used on the page.
You can also access and update client states in multiple page scripts. A common use case is
to keep track of values input by users in multiple form controls on a page. When the form is
submitted, a client script could then use all of the values stored in client state
parameters to create a new record with a data broker. A page can have one or more client
state parameters, which you can declare for a page through the UI Builder. You can then bind
a client state parameter to one or more components to share or act on the client state
parameter.

api.setState() calls are executed
asynchronously and do not necessarily update the UI immediately. If the value to set depends
on the currentValue of the client state parameter, or any of the
properties provided in the api object, you should use this variant of the
api.setState() method to avoid using outdated values.
{#api-setState_S_F__table_vlt_gyq_n4b__entry__3}{#api-setState_S_F__stateParm-entry-api}

| Name | Type | Description |
|-|-|-|
| stateParm | String | Name of the client state parameter to update. This name must be declared in the client state parameters of the associated page. For additional information on declaring client state parameters, see [Work with client state parameters](https://www.servicenow.com/docs/access?context=state-parameters&version=xanadu&pubname=xanadu-application-development&ft:locale=en-US). |
| callbackFn | Function | Callback function to execute to obtain the value. |
[Table 54. Parameters]

{#api-setState_S_F__table_vlt_gyq_n4b} {#api-setState_S_F__table_wlt_gyq_n4b__entry__2}

| Type | Description |
|-|-|
| None |   |
[Table 55. Returns]

{#api-setState_S_F__table_wlt_gyq_n4b}  
This example shows how to use api.setState to log users into a page.

    function handler({api, event}) {
      const {name, value} = event.payload;
      if (name === 'username' || name === 'password') {
        // Update the loginParameters state object with the username/password value
        api.setState('loginParameters', ({currentValue}) => {
          return {
            ...currentValue,
            [name]: value
          };
        });
      }
    }

## api - api.state.\<client_state_parameter_name\> {#ariaid-title31}

Current value of the specified client state parameter.
{#api-state__table_yk3_rmb_n4b__entry__3}

| Name | Type | Description |
|-|-|-|
| \<client_state_parameter_name\> | Any. The available client state parameters are dependent on the page configuration. | Name of the client state parameter. Available client states are dependant on the client script implementation. To access the available client states, use the following: `api.state.<client_state_name>`. For example: function showRelatedLists({api}) { return !api.state.isCustomListSelected; } Note: These property values are read-only. To update a client state parameter, use [api.setState()](https://servicenow-prod.fluidtopics.net/0iS74DaTo1jnkN1GBpOiXQ#api-setState_S_A "Sets the value of the specified client state parameter."). Mutating nested object values from scripts is not supported. |
[Table 56. Field]

{#api-state__table_yk3_rmb_n4b}

