#1 Client Scripts in ServiceNow | Overview
[Music] please subscribe to my channel and click on the bell icon to get the regular updates of my channel and do not forget to like comment and share hello everyone welcome to sas word service now this is short series of learning client scripts in servicenow in details in this series you will learn about different types of client scripts their major scenarios and practical examples overview of client scripts so we will start with overview of client scripts in which you will learn what is a client script in servicenow and what different types of client scripts we have in servicenow system what is client script a client script is a client-side script that runs the client-side code when event occurs on the client which is the user's browser like loading of the form form submission change of a field value on the form the table of client script is sys underscore script underscore client where all client script records are stored in servicenow system you can use client script to complete the tasks like validating form before submission setting a field value when another field is updated with new value on the form types of client scripts there are four types of client script in servicenow onload on submit on change and on cell edit these types are basically the time when client script should be running we will talk about these different types of client scripts later in more details individually with practical examples ui where client script can be applied client scripts can run on different ui of service now like desktop mobile or portal you can select all option as well to run one client script in all types of ui or you can select one of them so it depends what kind of requirement you have from your customers and clients let's see what type of actions can be performed by client scripts so making feels hidden or visible on the form in that case that kind of action can be performed by client scripts showing alert popup on the form on the basis of some conditions setting the value of a field on the form showing a confirmation box for any action to proceed on the form performing validations on edit or fields in a list of records of a table so if you have list of brackets in a particular table and you want to perform some validation when somebody changes the value in the list view in the fields in that case if you want to perform some validation then client scripts will be used client script form so let's see client script form and its field in service now so here is the form of client script so when you will create a new form basically new record of client script then you will see this particular form and the first field of this form is name where you can put the name of the client script you want to create next is table field in which you select the table for which client script needs to run then you have ui type where you can choose type of ui you want to run your client script like mobile portal desktop or all the next is main field which is basically decides when this client script should run and that is type then we have application scope that for for which application scope you want to create this client script that you can select over here basically it will be automatically be populated when you will select the scope then you have active check box to make this client script enable or disable then we have inherited checkbox now you can select this check box if you want to run created client script for inherited tables as well as an example if you have created a client script on task table and you want to run the same client script for incident or problem table then you can check this check box then you have global field which you can select to run client script for all type of views of the form so if you have multiple views on a form and if you want to run same client script on different views all the views you have then you can make that client script as global client script else you can uncheck this box and specify a view as well then you have description field where you can provide details of the client script and then next is script field before that we have message so if you want to populate some messages on the form you can also mention those messages over here which will be automatically populated and then next is a script field where you write the code in javascript and which will be executed when same client script will be triggered so when condition will be matched so you are selecting the ui type you are selecting the type you are selecting the table if everything will be matched then whatever code you will write in this script field that will be executed so whatever action it should take as per the script system will take that action now unlike business rules client scripts cannot be configured by selecting values to perform any action so if i talk about business rules in business rules in even if you don't write script you can still achieve some functionality with the help of configuration but if i talk about client script you definitely have to write a script a code in javascript language to perform some action in servicenow system servicenow provides a lot of api and methods which you can use on client-side code additionally you can use them in client script as well to perform some action on the client and the major apis we have g underscore form g underscore user and glide ajax and there are different methods which you can use to achieve different kind of functionalities now there are a lot other apis and methods as well however these are majorly used apis which you will use in your daily development as per the requirement you get from your customers and clients now let me create a client script in which i will show a message on the problem form when it is loaded it's just a quick example but in further series you will see individual examples for different types of client scripts we have different scenarios as well so that you can understand each client script in details so let's create the client script with a message on problem form this is my personal developer instance so as per the requirement as per the use case i have to show a message on problem form when it is loaded maybe i will show an alert because as of now i just need to show you the example that what exactly the client script is and then later on in the series you will see different types of client scripts with proper example with practical examples so let me show you quickly that how you create a client script simple client script so we have to show that message and alert on problem form so for that what i will do i will go to client script which is under system definition i will click on client scripts now here i will click on new you will see this new form of client script now here i will provide the name so let's say first demo of client script i can select the table over here and that's problem because i have to run this client script on problem so i will select the table problem ui type i can keep let's say desktop for now so you can see we have three options desktop mobile slash service portal and then all but i'm not going to select these two so i will keep desktop for now now here you have to select the time that when exactly you want to run it and if i talk about the current use case that is on load so i will click here and i will select onload it will automatically populate this function and here i will just type alert and i will just put it in the string this is a demo client script that's it so i will click on save now if i will open the problem form you will see this alert the same alert which we have mentioned over here because that's the requirement you have to show that alert on the problem form when it is getting loaded so what i will do i will quickly go to the problem list so we have these rackets and i can open any racket so i will click on this one if i will open this racket now it is loading now on load of this form that method should be populated so you can see it is showing this alert this is a demo client script and i can click on close that's it so you are done so this is how you create a client script now in further series you will see different types of client scripts we have in service now with their practical examples thanks for watching this video have a great day
https://www.youtube.com/watch?v=AqUY98OToGY