Client Side Scripting Flashcards
What are the two types of scripts found in ServiceNow?
Client Side & Server Side
———————————————————————
📁 Client Side Scripting Developer Documentation
Where do client scripts execute?
Within a user’s browser
———————————————————————
📁 Client Side Scripting Developer Documentation
When do client scripts execute?
When forms are loaded, changed, or submitted
———————————————————————
📁 Client Side Scripting Developer Documentation
What are the main 2 reasons an onLoad client script would be used?
To manipulate a form’s appearance
or manipulate a form’s content
———————————————————————
📁 Client Side Scripting Developer Documentation
When does an onLoad script execute?
When a form is loaded.
———————————————————————
📁 Client Side Scripting Developer Documentation
When does an onChange script execute?
When a particular field’s value changes.
———————————————————————
📁 Client Side Scripting Developer Documentation
Why would you use an onChange client script?
An onChange client script will allow you to monitor fields that contain values of interest and modify the values or attributes of another field based on changes to your field of interest.
———————————————————————
📁 Client Side Scripting Developer Documentation
When do onSubmit scripts execute?
When a form is submitted
———————————————————————
📁 Client Side Scripting Developer Documentation
Why would you use an onSubmit client script?
Validate field values
———————————————————————
📁 Client Side Scripting Developer Documentation
What type of API is GlideForm?
Client-side
———————————————————————
📁 Client Side Scripting Developer Documentation
What does the GlideForm API do?
Provides methods for managing form and form fields.
Some Examples:
- Retrieve a field value on a form
- Hide a field
- Make a field read-only
- Write a message on a form or a field
- Add fields to a choice list
- Remove fields from a choice list
———————————————————————
📁 Client Side Scripting Developer Documentation
What syntax is used when implementing methods from the GlideForm API?
g_form.<method></method>
———————————————————————
📁 Client Side Scripting Developer Documentation
What types of scripts support the use of the g_form object?
Client side scripts
———————————————————————
📁 Client Side Scripting Developer Documentation
Can you list off some of the methods commonly used with the g_form object?
- getValue()
- addOption()
- clearOptions()
- addInfoMessage()
- addErrorMessage()
- showFieldMessage()
- clearMessages()
- getSections()
- getSectionName()
———————————————————————
📁 Client Side Scripting Developer Documentation
What does the GlideUser API do?
Provides methods and non-method properties for finding information about the currently logged in user and their roles.
———————————————————————
📁 Client Side Scripting Developer Documentation
What syntax is used when implementing methods or accessing non-method properties from the GlideUser API?
g_user.<method></method>
———————————————————————
📁 Client Side Scripting Developer Documentation
What information would the following code display in a brand new ServiceNow developer instance?
g_user.firstName
System
———————————————————————
📁 Client Side Scripting Developer Documentation
What information would the following code display in a brand new ServiceNow developer instance?
g_user.lastName
Administrator
———————————————————————
📁 Client Side Scripting Developer Documentation
What information would the following code display in a brand new ServiceNow developer instance?
g_user.userName
admin
———————————————————————
📁 Client Side Scripting Developer Documentation
What information would the following code display in a brand new ServiceNow developer instance?
g_user.userID
This returns the sys_id for the individual
———————————————————————
📁 Client Side Scripting Developer Documentation
What types of scripts support the use of the g_user object?
Client side scripts
———————————————————————
📁 Client Side Scripting Developer Documentation
Can you list off some of the methods most commonly used with the g_user object?
- hasRole()
- hasRoleExactly()
- getFullName()
———————————————————————
📁 Client Side Scripting Developer Documentation
What are the similarities between client side scripts and UI policies?
&
What are the differences between client side scripts and UI policies?
They are both client side logic that governs form and form field behavior.
&
UI policies don’t require any scripting
———————————————————————
📁 Client Side Scripting Developer Documentation
What are UI policy actions?
Client side logic within a UI policy, used to set three field attributes:
- Mandatory
- Visible
- Read Only
———————————————————————
📁 Client Side Scripting Developer Documentation
What do UI Policy Scripts do?
They use the client-side API to execute script logic based on whether the UI Policy condition tests true or false
———————————————————————
📁 Client Side Scripting Developer Documentation
Why would you use a UI Policy Script?
To create complex conditional checks or to take actions other than setting field attributes (mandatory, read-only, or visible)
———————————————————————
📁 Client Side Scripting Developer Documentation
Which runs first, UI Policies or Client Scripts?
&
If there is a conflict of logic, which of the two is applied?
Client Scripts execute first
&
UI Policy logic applies in this scenario
———————————————————————
📁 Client Side Scripting Developer Documentation
Which of these classes are part of the ServiceNow client-side API?
More than one may be correct
- GlideSystem (gs)
- GlideUser (g_user)
- GlideDateTime
- GlideDate
- GlideForm (g_form)
- GlideUser (g_user)
- GlideForm(g_form)
———————————————————————
📁 Client Side Scripting Developer Documentation
True or False?
A single client script can execute its script logic when a user loads a record into a form AND when a user saves/submits/updates a form
False
A single client script can be either onLoad OR onSubmit but cannot be both. The Type field determines whether a Client Script is an onLoad or an onSubmit client script
———————————————————————
📁 Client Side Scripting Developer Documentation
What are client scripts used for?
To manage forms and form fields
———————————————————————
📁 Client Side Scripting Developer Documentation
What are the three types of client scripts?
onLoad, onChange, and onSubmit
———————————————————————
📁 Client Side Scripting Developer Documentation
Why should onLoad client scripts be used sparingly?
They impact form load times.
———————————————————————
📁 Client Side Scripting Developer Documentation
What are the 5 parameters passed to the onChange() client script automatically by ServiceNow?
control, oldValue, newValue, isLoading, isTemplate
———————————————————————
📁 Client Side Scripting Developer Documentation
What does the automatically passed “control” parameter reference within the context of an onChange client script?
The control parameter contains information to reference the field for which the client script is written.
———————————————————————
📁 Client Side Scripting Developer Documentation
What does the automatically passed “oldValue” parameter reference within the context of an onChange client script?
The oldValue parameter contains the value that was present in the field on form load - before the change.
———————————————————————
📁 Client Side Scripting Developer Documentation
What does the automatically passed “newValue” parameter reference within the context of an onChange client script?
The newValue parameter contains the value that is now in the field after the change has taken place.
———————————————————————
📁 Client Side Scripting Developer Documentation
What does the automatically passed “isLoading” parameter reference within the context of an onChange client script?
The isLoading parameter contains a boolean value indicating whether change came from a form load or not.
———————————————————————
📁 Client Side Scripting Developer Documentation
What does the automatically passed “isTemplate” parameter reference within the context of an onChange client script?
The isTemplate parameter contains a boolean value indicating whether the change occurred due to population of the field by a template.
———————————————————————
📁 Client Side Scripting Developer Documentation