0% found this document useful (0 votes)
42 views

Client Scripts

Uploaded by

Madhavi Venkat
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views

Client Scripts

Uploaded by

Madhavi Venkat
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 30

Client Scripts

Client Scripts are allowing to user to run Java Script on client side (Browser Window) when
client based events are occurred or executed
Such as when a form was, Loads and or submitted form and when a field value is changed and
when you edit cell value from list view
We can be able to use client scripts to configure Forms, Form Fields and Field Values while
user is using any particular form.

Client Scripts can do some below activities like


1. Make it as field Mandatory or Optional
2. It is used to display message based on Field Values
3. Make is as field Read only and Writable
4. Make it as filed Visible and Invisible
5. Add and modify the options in a choice list based on user’s role
6. Giving Info and Error Messages to customer
7. Add and Remove the choice values
8. Set and Get values from fields
9. Display Flash messages
10. Add Information Message to customers

Types of Client Scripts


We have 4 types of client scripts in Service Now such as

onLoad ()
OnLoad client script will runs when the system first loaded on the form and before users can
enter data. Typically, onLoad () client scripts mainly running from client-side of the current form
and t is used to set default record values.

onChange ()
on Change will runs when a particular field value changes on the form. then we can use
onchange client script

onSubmit ()
it will run when a form is submitted. Typically, onSubmit () scripts validate things on the form
and ensure that the submission makes sense. An onSubmit () client script can cancel form
submission by returning a value of false.
OnCellEdit ()
It will run when a user tries to change a cell value from list view then onCellEdit client script will
be execute and provide result

Why Client Scripts?


Client scripts can be reducing the amount of time it takes while a user’s to complete a form.
If we create client scripts is used controlling a field values on a form, you must use another
method to control these field values in a list.

Using by client scripts we can perform following operations:


1. We can restrict a user List Editing for the particular table.
2. Will create particular Business rules or we can access controls for list editing.
3. We can create Data policies and UI Policy
4. On list view we can restrict a user onCellEdit client script.
5. Check validation when we submit form
6. Validation will check when form was loaded
7. It can be reduced the need for time-consuming from server lookups.
8. g_scratchpad and asynchronous GlideAjax lookup are simple way get the information
from the server Glide Record and g_form. getReference() methods are also available
for retrieving server Information.
9. However, these methods are no longer recommended due to their performance impact.
So always we can recommend to use g_scratchpad and asynchronous GlideAjax

Use of g_scratchpad
The g_scratchpad object will passes the information from the Server to the Client, when we
want to get required information that is not available on the particular form.

Where Our Client Scripts Run


With the exception of onCellEdit () client scripts, remaining client scripts only apply on
particular forms and search pages, onLoad (), onChange (), onSubmit ()
If you want create a client script to controlling field values on a form, you should be use one of
these other methods to control field values when on a list.

1. We can create an access control rules to restrict user who can read and edit field values
on your form. Create a business rules to validate content in form.
2. Create a UI Policy and Data policy to validate content in form.
3. Create an onCellEdit () client script to validate content in list view.
4. Disable list editing for the particular table

Client side Glide API classes


GlideAjax : This object is used to execute server-side script from the client

GlideForm : Customize our forms

GlideList2 : Used to customize (v2) lists, including normal lists and related lists.

GlideUser : This object is used to get session information about the current user and roles.

GlideMenu : It is used to customize UI Context Menu items.

GlideDialogWindow : Use this class to display a dialog window

Client Scripts Exercises


Exercise: 1 Table Incident
Requirement: When Incident Form Loaded then some filed are make Mandatory, Read only,
and invisible and add an Information Message to define fill all mandatory fields
1. Number and Priority Fields are Read only
2. Caller and Short Description fields are Mandatory
3. Configuration Item field is should not be seen (Invisible)
4. Display an Information Message top on the form if the record is new

Client Script Type


OnLoad

Procedure
1. Navigate to System DefinitionClient Scripts
2. Open Client Scripts
3. Click on New

4. Fill Clients Scripts Form


5. Name: Initial Form Validation
6. Table: Incident
7. UI Type: All
8. Type: OnLoad
9. Script

10. Open New Incident form check the validation


11. Incident  Click on Create New
Exercise: 2 Table Incident
Requirement
1. When Incident State is On-Hold Then On Hold Reason field should be Visible and
Mandatory
2. Add warning message below hold reason field that is ‘’Please select at least one hold
reason’’

Client Script Type


OnChange

Procedure
1. Navigate to System DefinitionClient Scripts
2. Open Client Scripts
3. Click on New
4.Script

5. Open New Incident form check the validation


6. Incident  Click on Create New
7. Change state value to On-Hold
8. Check on hold reason field is Visible and Mandatory
9. Follow below screen shot for reference
Exercise: 3 Table Incident
Requirement: Any customer after submitted (Priority 1-Critcal) incident
1. We need to display one alert message to customer about Criticality (Are you submitting
Priority one ticket)
2. Include Ok and Cancel Buttons also

Client Script Type


OnSubmit

Procedure
1. Navigate to System DefinitionClient Scripts
2. Open Client Scripts
3. Click on New
4. Script

5. Open New Incident form check the validation


6. Incident  Click on Create New
7. Select Impact-1 and Urgency-1
8. Click on Submit Button
9. Follow below screen shot for reference
Exercise: 4 Table Incident
Requirement
1. When Incident state is Resolved Then Resolution Code and Reolution Notes are
mandatory
2. Assigned to and Assignment Group should not be seen

Client Script Type


OnChange

Procedure
1. Navigate to System DefinitionClient Scripts
2. Open Client Scripts
3. Click on New
4. Script

5. Open New Incident form check the validation


6. Incident  Click on Create New
7. Change state value to Resolved
8. Check validation on below screen shot for reference
Exercise: 5 Table Incident
Requirement
1. If Selected Caller is VIP in Incident table, then Impact and Urgency field values setup
1-High.Impact-High and Urgency High then Priority 1- Critical set automatically
2. Impact and Urgency fields should be read only on above condition
3. Display on alert message on browser that is (Caller is VIP!)
Developer TIP: Make one Caller VIP (Fred Luddy) from user record (Already we know how to
do this)

Client Script Type


OnChange

Procedure
1. Navigate to System DefinitionClient Scripts
2. Open Client Scripts
3. Click on New

4. Script
5. Open New Incident form check the validation
6. Incident  Click on Create New
7. Select any VIP Caller like Fred Luddy
8. Check validation on below screen shot for reference
Exercise: 6 Table Incident
Requirement
1. If customer selected Incident Category is Inquiry/Help, then Subcategory
field should be hide
2. Remove choice 1-High from Impact and Urgency fields
3. Display an Error Message below impact field (Low impact is not prefer high
priority)
Client Script Type
OnChange

Procedure
1. Navigate to System DefinitionClient Scripts
2. Open Client Scripts
3. Click on New

4. Script
Exercise: 7 Table Incident
Requirement
1. When current incident state is New then remove all choices from State field
Choices need to be removed (In-Progress, On-Hold, Resolved, Closed, Cancelled).

2. When current incident State is In-Progress or On-Hold then remove all choices from
State field Choices need to be removed (New, Closed,).

3. When current incident State is Resolved, then remove these all choices
Choices need to be removed (New, In-Progress, On-Hold, Cancelled)

4. When current incident State is Closed, then state field should be Read-only

Client Script Type


OnLoad

Procedure
1. Navigate to System DefinitionClient Scripts
2. Open Client Scripts
3. Click on New
4.Script
1. Open New Incident form check the validation
2. Incident  Click on Create New
3. If current incident state is New, then rest of states should not be seen
4. If current incident state is In-Progress or On-Hold, then New and Closed States should
not visible
5. In Resolved state display only Closed state value
6. If state is Closed State filed should be Read-only

Exercise: 8 Table Incident


Requirement: If incident state is Closed then all fields make read-only
1. If incident state is closed, assigned to, assignment group, category, subcategory, impact,
urgency, contact type, short description, caller field are make readonly
2. Attachment Icon should not see in Closed record
3. All Related Lists should be hide

Client Script Type


OnChange

Procedure
1. Navigate to System DefinitionClient Scripts
2. Open Client Scripts
3. Click on New
4. Script

1. Open New Incident form check the validation


2. Incident  Click on Resolved Module
3. Change the state value to Closed then some field are display in Read-only
4. We couldn’t see Attachment Icon and Related Lists
Exercise: 9 Table Incident
Requirement: When customer changed incident Priority field value then work notes should
be mandatory
1. If record is New or Form isLoading or oldValue == newValue same then work notes
field should not mandatory
2. When customer changed Priority 1 to 2 then work notes field make Mandatory

Client Script Type


OnChange

Procedure
1. Navigate to System DefinitionClient Scripts
2. Open Client Scripts
3. Click on New

4. Script
5. Open New Incident form check the validation
6. Incident  Click on Create New Module
7. Change the Priority to 1 then Save it
8. Again change the Priority to 2 then get info message to fill work notes mandatory
Exercise: 10 Table Incident
Requirement: User restriction, not allowing update the cell value from Incident List View
1. Any customer try to change incident state value to 7- Closed action will be cancel and
display alert message to customer
2. Alert Message (System not allow user to update cell value)

Client Script Type


OnCellEdit

Procedure
1. Navigate to System DefinitionClient Scripts
2. Open Client Scripts
3. Click on New

4.Scri
pt
4. Open Incident List View and check the validation
5. Incident  Click on All Module
6. Change the state value to 7-Closed
7. Get Error Message (System not allowing user to update cell value)

Exercise: 11 Table Incident


Requirement:
1. When user submit incident form need to display Assigned to Name as alter message
2. Give confirmation message also

Client Script Type


OnSubmit

Procedure
1. Navigate to System DefinitionClient Scripts
2. Open Client Scripts
3. Click on New
4. Script

5. Open New Incident check the validation


6. Fill Assigned to field and Submit form
7. Display alert message and and given confirmation message
Exercise: 12 Table Incident
Requirement: Auto assign the value to Assignment Group depends on category
1. If Category is Network auto assigned Network Assignment Group
2. Category is Hardware auto assigned to Hardware Assignment Group
3. Category is Database auto assigned to Database Assignment Group
4. Category is Software auto assigned to Software Assignment Group

Client Script Type


OnChange

Procedure
1. Navigate to System DefinitionClient Scripts
2. Open Client Scripts
3. Click on New

4. Script
5. Open New Incident check the validation
6. Select the Category is Software then ticket is auto assign to Software Assignment
Group
7. Select Remaining Category Also Similarly check the validation
Exercise: 13 Table Incident
Requirement: Auto set Caller value into caller field depends on current logged in user
1. Display alert message say Hello message with logged in user full name

Client Script Type


OnLoad

Procedure
1. Navigate to System DefinitionClient Scripts
2. Open Client Scripts
3. Click on New

4. Script

5. Open New Incident check the validation


6. Click on Create New module
7. Click on Ok button
Exercise: 14 Table Incident
Requirement: Date Validation between two fields for Incident table
1. Create Two custom fields in incident tables (Start Date, End Date)
2. Start date shoul should be always before End date
3. Start date should not equal to End date
4. Give me Error Message under End date field

Client Script Type


OnChange

Procedure
1. Navigate to System DefinitionClient Scripts
2. Open Client Scripts
3. Click on New
4. Script

5. Open New Incident check the validation


6. Click on Create New module
7. Select Start and End date (Start date should be after End date ) check error message
8. Check another validation both dates shoul not equal
Exercise: 15 Table Incident
Requirement: Hide Resolution Information section when state is not equal to Resolved
1. When Page Is Loading and state is not equal to Resolved then hide Resolution
Information section otherwise display section

Client Script Type


OnChange

Procedure
1. Navigate to System DefinitionClient Scripts
2. Open Client Scripts
3. Click on New

4. Script
5. Open New Incident check the validation
6. Click on Create New module
7. When form is Loaded and state not equal to Resolved hide the Resolution Information
Section

You might also like