onChange

The onChange client script runs when a selected field is changed on the form. It is important to note that an onChange script will also run when the form is loaded. This type of script is often used to auto-populate other fields on a form, based on data in the field the onChange script is running on. For example, if a user is selected on a form, other user data on the form, like company and job title, could be populated using an onChange script.

In the same way that ServiceNow provides a script function in onLoad scripts, an onChange function is also provided. This is slightly more complicated, so let's take a look:

function onChange(control, oldValue, newValue, isLoading, isTemplate) {    if (isLoading || newValue === '') { return; ...

Get Mastering ServiceNow Scripting now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.