Client scripts allow the system to run JavaScript on the client (web browser) when client-based events occur, such as when a form loads, after form submission, or when a field changes value.

Use client scripts to configure forms, form fields, and field values while the user is using the form. Client scripts can:

  • make fields hidden or visible
  • make fields read only or writable
  • make fields optional or mandatory based on the user's role
  • set the value in one field based on the value in other fields
  • modify the options in a choice list based on a user's role
  • display messages based on a value in a field
Warning:

Client scripts are intended to optimize the user experience on a form. Client scripts are not meant to protect unwanted access to data.

To prevent unwanted access to data, ensure that sensitive fields are hidden or read-only through ACLs or data policies.

For more information, see Access Control List Rules or Data policy.

Where client scripts run

With the exception of onCellEdit() client scripts, client scripts only apply to forms and search pages. If you create a client script to control field values on a form, you must use one of these other methods to control field values when on a list.
  • Create an access control to restrict who can edit field values.
  • Create a business rule to validate content.
  • Create a data policy to validate content.
  • Create an onCellEdit() client script to validate content.
  • Disable list editing for the table.
Note: Client scripts are not supported on ServiceNow mobile applications.

Client script form