Lessons › Domain 2: Application User Interface (20%) › Lesson 6
Client-side Scripting
About 16 minutes · Last checked against the CAD blueprint (January 2026): 4 December 2026
Step 1 · Learn
Scripts that run in the user's browser
Client scripts run in the browser, on a form or list. They react to what the user does, for example by showing a message or setting a field when another field changes.
Types
| Type | Runs when |
|---|---|
| onLoad | The form opens, before the user can work on it |
| onChange | A specific field's value changes, including while the form loads |
| onSubmit | The form is saved or submitted; returning false stops the save |
| onCellEdit | A field is edited in a list |
An onChange script receives isLoading; check it so the script does not run its logic while the form is still loading.
Client-side APIs
g_formworks with the form:getValue(),setValue(),setMandatory(),setDisplay(),setReadOnly(),showFieldMsg(),addInfoMessage().g_userdescribes the logged-in user:userName,userID,firstName,hasRole().GlideAjaxcalls a client-callable script include on the server and returns the answer asynchronously, for example withgetXMLAnswer().
Good practice
- Prefer a UI policy when you only need to make fields mandatory, read-only or hidden.
- Do not use synchronous server calls, which freeze the browser; use GlideAjax with a callback.
- Avoid
g_form.getReference()without a callback for the same reason. - Keep onLoad scripts light, because they slow down every form load.
Debugging
Client scripts are debugged in the browser: use the browser's developer console with console.log(), check for script errors there, and use the Field Watcher to see which scripts and policies change a field.
Step 2 · Do
Script the loan request form
Make the form react to the user, using the right client-side tools. This is a practice environment of our own design, not the ServiceNow product. Complete the tasks in the task list.
Step 3 · Check
Exam-style questions
Select an answer and check it. Every answer includes an explanation.