3.client Script
3.client Script
ClientScripts
◦ What is client-side development?
◦ Client-side development, sometimes referred to as front-end development, is a type of development that involves
programs that run on a client's or user's device. Client-side developers focus on creating the part of a website with
which the user interacts.
◦ This type of development focuses on the front part of an application that users can see. Client-side developers
complete a variety of tasks, including:
Creating website layouts
Designing user interfaces
Adding form validation
Reviewing the performance of websites
Adding visual design elements like colors and fonts
Making website features more functional
Resolving any issues that users encounter on a site
Client-side Scripting:
Client script is a piece of JavaScript code that runs on your web browser instead of the server, thus returning an immediate response.
Using the Client Script, you can perform event-triggered UI actions on the client-side.
Runs the client side script when event occurs on the browser like loading of form, form submission, change of a field value on the
form
Client-side scripts execute within a user's browser and are used to manage forms and form fields.
For example, when a user fills the email address of a Lead/Contact, you can perform email discovery and automatically populate
relevant data in the form.
◦ Runs the client side script when event occurs on the browser like loading of form,or form submission,change of a field value on the
form.
◦ The Table of client script is sys_script_client.
◦ Where all client script records are stored in servicenow system you can use client script to complete the tasks like i.e validating forms
befor submission setting a field value when another field value is updated with new value on the form.
ServiceNow provides a lot of API and methods which you can use on client side code.To perform some
action in client and major API’s we have above three which you can use to achieve different kind of
functionalities.
• Place the cursor in a form field on form load
• Generate alerts, confirmations, and messages
• Populate a form field in response to another field's value
• Highlight a form field
• Validate form data
• Modify choice list options
Types of client script:
• OnLoad
• OnSubmit
• OnChange
• OnCellEdit
• OnLoad: On Load Client Script Runs when user opens the form and before user can enter the data on the
form. It is usually used to set default values on the form or showing message or popup while form is opened.
• If you want to take some action on the form when form is being is loaded.then you can use onload client
script.
◦ hgx
SCENERIO 1:
When P1 incident opened then there should be an alert which says “This incident is P1 Incident”?
O/P:
◦ SCENERIO 2:
◦ When New incident form is opened then caller should be an Populated Automatically with current logged In user?
O/P: caller will Automatically Populated.
◦ OnSubmit: OnSubmit Client Script Runs when form is submitted. It is usually used to validate things on the form before the
submission on the form
◦ Scenerio1:When p1 incident is created then it should ask user to confirm if p1 incident should be
created?
◦
Scenerio2:When network is assignment group category is hardware user should not be able to create incident.
In navigation bar search sys_user_group .LIST Search Network copy sys ID
SCRIPTING : OUTPUT:
Im not able to submit when I try to
submit the incident form
◦ OnSubmit client script is used to perform client-side validation of data before it is submitted to the server.
◦ When a user submits a form in ServiceNow, the OnSubmit client script can be used to validate the data entered in the
form fields. The script can be used to check for mandatory fields, validate input in certain fields, and enforce business
rules. If the validation fails, the script can prevent the form from being submitted and display an error message to the
user.
◦ Once the OnSubmit client script is created, it will run each time the form is submitted, and the validation logic will be
executed to ensure that the data is valid before it is sent to the server.
◦ OnChange: an OnChange client script is used to perform client-side validation of data when a specific field on a form
is changed.
◦ When a user changes the value of a field on a form in ServiceNow, the OnChange client script can be used to validate
the new value entered in the field. The script can be used to check for mandatory fields, validate input in certain
fields, and enforce business rules. If the validation fails, the script can display an error message to the user.
◦ Once the OnChange client script is created, it will run each time the specified field on the form is changed, and the validation
logic will be executed to ensure that the new value entered in the field is valid. If the validation fails, the script can display
an error message to the user.
◦ OnChange: OnChange Client Script Runs when Particular field value changes on the form.it is used when you want to perform some
action on client when field value changes.
◦ OnChange CS Parameters: Function onChange (control,oldValue,newValue,isLoading,isTemplate)