Supported client script types and APIs
Summarize
Summary of Supported client script types and APIs
This document details the types of client scripts and client-side APIs supported in ServiceNow's Service Portal as of the Xanadu release. It clarifies which client scripts can be used, necessary UI type settings, and highlights the supported client-side APIs compatible with mobile environments within the Service Portal context.
Show less
Client Script Support in Service Portal
- Catalog Client Scripts: Must have the UI Type set to All or Mobile / Service Portal. Scripts marked as Desktop are incompatible due to reliance on legacy APIs not supported in Service Portal.
- Validation Scripts: Also require UI Type set to All or Mobile / Service Portal. Validation scripts are used to verify user input on specific fields. For new instances, Service Portal includes default validation scripts such as XML, Script, Script (Plain), Email, and Version types. When upgrading, these scripts need to be manually activated for Mobile and Service Portal usage.
- UI Scripts: Require UI Type set to All or Mobile / Service Portal. Scripts marked as Desktop are unsupported. To call a UI script within a validation script, use the
guiscriptsglobal object, ensuring the UI script is not global and is set for Mobile / Service Portal or All. - UI Actions: All server-side UI actions are supported, except that
setRedirectURL()calls are ignored because Service Portal handles redirection differently. Client-marked UI actions are ignored by the form widget. - UI Policies: Supported if declarative. Scripting within UI Policies should be avoided unless necessary due to condition builder limitations.
- UI Macros and Formatters: Not supported as they depend on Jelly, which is incompatible with Service Portal.
Supported Client-Side APIs
The following client-side APIs are supported in Service Portal for client scripts triggered onLoad, onChange, and onSubmit:
- gform: Provides methods to manipulate form fields and UI elements, such as adding/removing options, showing error/info messages, setting field values, visibility, and mandatory status, and submitting forms.
- glist: Supports list operations like getting/adding/removing items and setting queries.
- gservicecatalog: Includes methods such as
isOrderGuide()to interact with catalog-specific data. - GlideAjax: Enables asynchronous server calls with methods to add parameters, execute calls, and handle callbacks. Synchronous methods like
getXMLWait()are not supported in Service Portal; asynchronous calls must be used instead. GlideAjax is not supported in widget client controllers. - GlideRecord: Allows querying and manipulating records, supporting asynchronous querying and standard CRUD operations.
- i18NV3: Supports localization with methods like
getMessage()for retrieving translated messages asynchronously.
Important notes:
- Client scripts set to Desktop rely on legacy APIs and are not supported in Service Portal.
- The
gformglobal object cannot be used in widget client controllers or UI scripts. - Use only client-side APIs supported in mobile environments when developing for Service Portal.
Some client scripts are not supported in Service Portal. Others must have a UI type set to All or Mobile / Service Portal. If using a client script in the Service Portal, only client-side APIs supported in a mobile environment can be used.
Client script support in Service Portal
| Client script | Description |
|---|---|
| Catalog client scripts | Service Portal requires that the UI Type field be set to All or Mobile / Service Portal. Client Scripts marked as Desktop rely on legacy APIs that are not supported in Service Portal. Before flagging a script as Mobile / Service Portal or All, make sure you are only using supported client-side APIs. |
| Validation scripts | Service Portal requires that the UI Type field be set to All or Mobile / Service Portal. Client Scripts marked as Desktop rely on legacy APIs that are not supported in Service Portal. Before flagging a script as Mobile / Service Portal or All, make sure you are only using supported client-side APIs. Validate user input in a specific field type using a validation script. In new instances, Service Portal includes XML, Script, Script (Plain), Email, and Version validation scripts by default. If upgrading from a previous release, the Mobile and Service Portal version is not active by default. You must activate the Mobile and Service Portal version of the validation script to validate user input in the Service Portal. See Activate Service Portal validation scripts. Note: To call a UI script within a Validation script, use the g_ui_scripts
global object. For more information, see GlideUIScripts.
Verify that the UI script has the Global field set to
false and UI Type set to Mobile / Service Portal or All. |
| UI scripts | Service Portal requires that the UI Type field be set to All or Mobile / Service Portal. Client Scripts marked as Desktop rely on legacy APIs that are not supported in Service Portal. Before flagging a script as Mobile / Service Portal or All, make sure you are only using supported client-side APIs. |
| UI Actions | All server-side UI actions are supported in Service Portal, although setRedirectURL() operations are ignored because Service Portal forms handle redirection in a different way than the platform. The form widget ignores any UI Actions marked as Client. |
| UI Policies | Supported, although you should use only declarative UI Policies. Avoid scripting unless the outcome cannot be achieved through the condition builder. |
| UI Macros | Not supported as UI macros use Jelly. |
| Formatters | Not supported as formatters use Jelly. |
Supported client-side APIs
Supported client scripting APIs for use in onLoad, onChange, and onSubmit client scripts.
For detailed class and method information, see the Client API reference.
| Class | Available methods |
|---|---|
| g_form |
Note: Using the variables.var_name notation with the g_form API
is not supported in Service Portal. g_form as a
global object cannot be used in a widget client controller or in a UI script. |
| g_list |
|
| g_service_catalog | isOrderGuide() |
| GlideAjax |
Note:
|
| GlideRecord |
|
| i18NV3 | getMessage(String messageKey, Function callback) |