Catalog Client Script Examples ServiceNow | Scripting Demo of All types of Catalog client Script

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello friends welcome back to my youtube channel basico service not learning so in today's video we are going to explore catalog client script and we will also do a practical implementation of the same so let's begin so what is a catalog client script so catalog client script is a javascript code which executes when user orders and catalog item okay and catalog client script executes on a client side there are three types of catalog client scripts onload on change and on submit okay so if we are talking about like a difference between a catalog client script and a client script so the difference is that in catalog client script we have three types of client scripts but in a client script actually we have four types that is on load on change on submit and on cell added and the second difference is that catalog client script only executes on catalog items or available sets right but a client script executes on a specific table such as like incident problem change etc etc right when we write a client script then we select a table that on what table we want to execute but this catalog client script will execute only for a catalog item for which we are writing code for for it so let's do a practical implementation and understand the concept of a catalog client scripts all of the three types in detail and will do a scripting for any specific use case okay so let's navigate to my servicenow personal developer instance so friends this is my servicenow personal developer instance so here we are going to implement a use case so let's see a use case also the use case for today is that below customization has to be done in demo sr catalog item okay so there is a catalog item in the service catalog the name of the catalog item is demo sr catalog item so below is the requirement which we have to customize in that particular demo sr so here in this video i am going to implement customizations for all the three types of catalog uh catalog client scripts like onload on change and on submit so for onload what we are going to implement that logged in username should be populated in requester field along with email and business phone number of a requester so let's first open the service catalog item and then we will see that what all changes we want to do there okay so here let's navigate to service catalog in self service we have service catalog okay and in the hardware we have this service catalog items where we are going to do some customizations so see here we have a form okay where we have lots of fields so as well as the first requirement logme username should be populated in requester field along with email and business phone number of a requester means this the question name email id and business phone number will get populated once the user open this particular form now a second requirement is up on change that on the change of a request email and phone number will get changed accordingly let's say if the request name is given over here and user change the requester name then email id and business phone will get auto populated or updated automatically now the third requirement is on some uh on submit catalog line descript that is requirement field value cannot be null on submission means if we are submitting the form or we are ordering a form then that requirement filled value cannot be null means user has to select any of the value from it the second requirement is that strong date cannot be greater than up to date means if user is giving a date over here from date to till date for which the laptop has been assigned to a user then from date will not be greater than to a to date so these requirements we have to cater through catalog client script okay so let's see how we can implement it so to implement the requirement what we have to do we have to type a maintain item over here and then we have to search this catalog item demo sr i am opening this mountain item in a new tab where we have see demo as a catalog item so i am opening this catalog item form from here see in the below we have a rated list where we have options for variables variable set catalog ui policies catalog client scripts okay and lots of other options like catalog categories so today we are going to explore this section that is catalog client script from here we can create a new catalog client script so i am clicking on new see once we click on new so in this form we have a section such as script where we can write a script as well so here i am going to write a first requirement that is on load okay so i am saying uh i'm giving name over here you can give any name download client script then you where you want to apply is to you want to write it for a catalog item or a variable set so i'm saying for a catalog item active is checked ui tab you can select accordingly then application then type see all the three types are displaying over here so i'm going to write an unload client script then we have a demo sr catalog item that is selected the catalog item for which we are writing this script then if you want to apply it on a requested item or catalog task you can click on the check box as well but currently i am writing this code for a catalog item view so that's why this particular checkbox is checked so on load what we wanted requester name email and phone number will get display so question name of our login user so we can get a login username we can get through a gender user object right from that user class so i'm saying g underscore user dot get full name so this particular syntax will provide me a full name of a login user so what i will do i will populate this in a field that is request so i will open the form also that we can get a name of a variable so here the name of a variable of a requester is where we want to populate the details that is request underscore name okay so i am going to write here generous perform that set value that is in this field i want to set the value of our login username so this syntax will populate the login username now we want a email and a phone number of a request so that information we will get from a user table okay because requested details are populated in a user table so just a second i'm just opening a user table to give you a brief understanding for the same so here in the organization we have users see that is system okay descript so from here we can get this business phone number and we can get email id so for that what we have to do we have to write a glide record for the same so here let's say so here we are going to write a code now okay so now what we will do we will do a add query or we will perform a query so we will perform query from a csid because from g underscore user or from a glide user table we can also get a csid of a user so let's say gr sorry gr dot add query then i am saying says id and in this from this syntax gene response user dot user id i can better see id of a user okay now dot query and i'm saying okay i'm using gr dot just a second here i have to write while rdq gr dot next if there is a record or while there is a record then it will perform the task which you want which you want the script to be performed so here i am saying that i want a record which needs to be filled on field called set value and fill this phone so the field of phone is business phone and email id is a field of email okay so here i'm going to just a write like this i'm seeing here i'm saying this req object dot i'm saying i believe uh just a second here i want this value right business phone that is phone and email is email okay so here phone that is okay it will give us the phone value and now let's add a code to populate email field okay uh set value we have email i believe that will name means email id okay and then now we are done with the code let's save the code and let's see okay so now let's navigate to a catalog item and load the form let's see whether code is working or not so i click on this see when the form loads all the information requests the name email id and business phone get populated okay so in this way we have written the onload client script now we have to fulfill the second requirement the second requirement is on change on change is basically on the change of requester email business phone number will get changed accordingly means that if we change the requester from here let's say if i have selected abraham lincoln then the email id and phone number will update according to the request name automatically okay so for what for that what i'm going to do is that i'm going to write uh another code that is uh it is on change client to script so i'm going over here i'm saying okay this so here i'm saying on change script you can give a name over here now what we have to do we have to select the types that's i have selected on change once i click so here the new field gets appear that is variable name so the in variable name i will find all the variable names over here so i will select the variable name of that field where we want that when the user change the value on that field then the code will get execute so let's say as per the requirement we have to select the requester name that when the requestion name get changed then the code will get executed so whatever code we have to write we have to write over here so what i will do i will copy some of the code from onload here and i will paste that code over here okay because anyhow we need to perform a query on a system user table because we need a phone and email from the system desktop user table so here what i'm going to do is that i need a cis id of a user okay because this will not work because this g underscore user will work only for the login user but here if we change the value to some other user let's say abraham lincoln's abraham lincoln is not a logged in user so it means glad user properties or classes or method will not work over here okay so when the user change the value then i want that this id of that user will be stored in a specific variable so i'm using the underscore form dot get value and then i'm saying the field name is request okay see i'm saying there's a store that's this id in a specific variable request okay so friends when we are getting a value from a reference field then it always give back a society of that user okay if we are talking about like in terms of multi uh multi line text single land text then it will give the value which is populated in a field but in terms of reference field it will give us a society of that user okay so now this is giving me a sec id of a user so what i will do i will copy this this id variable over here and i will paste this variable over here it means whatever society i am getting from here will perform a query over here society and this is id which i'm getting from here and the code is done let's save it so now let's execute the script again to see whether changes is done or not see i am just loading the page again now this is a brand linker will change to system administrator automatically because the form on load client script will work see now if i change the value to some other user let's say apple tutor now see this email id get changed business phone number will get changed it means on change client script is getting executed on the change of a particular field so i believe now you have an understanding of on load and on change now the third requirement is that on submit that submit what you want the requirement will value cannot be null or none on submission and the from date field cannot be greater than a to date so now we are going to write a third one uh the msa catalog item okay so here we have two already available now i'm writing the third one that is on submit client script so here everything is same what i have to select i have to select the type i have selected on submit now i have to write to the so here we have to write the code for on submit so what i can i'm going to do is that i'm navigating over here i'm tapping maintain items so that i can open that request and see the variable names from here okay so here we have uh variables so i have to write the code for this requirement and from date and two dates the name of the fields are requirement from underscored to underscore it okay so let's navigate to the section where we have to write the code on submit on change so here we have to write the code so let's say requirement cannot be null so i need to fetch a value from there something the underscore form dot get value from what field requirement right so what it will do it will give us a values which is selected in a drop down in a requester field here okay so if it is sorry if it is none or if it is none means blind then what will happen it will give us an error message and not allow the form to be submitted okay so i'm saying none so i'm saying it will show us a error message the underscore from error message please select [Music] yes we will force a user to select a value from here requirement okay now we also have to get a code for form date and due date okay so now proceed further i'm saying return so return false is basically is that whenever the code enters in if block then the form will not get submitted because it is returning a false from here now i'm saying else if true date and from date so it means we need to fetch the values from the two right field and the formula excludes i'm fetching the value and storing in a variable from that that value [Music] what i i'm going to do same where form dot value okay see i have already showed that from where we can the variable values we can get from here like from underscore that to underscore it right so here i have a formula escorted and to underscore it so now these two variables will have values what the user have given in that particular form now so i am saying if so now as press requirement uh from date will not be greater is greater than it will displace a message that you underscore form dot add error message that and along with this what we will do we will also add this particular scenario let's see here so that some permutation computation okay because user can perform any scenario this particular code okay so what happen if you just select the values requirement as none and from date is greater than two there then this particular code will execute means it will sort both the messages that the value is null and the form date is greater than the truth okay and it will not allow to submit the form so if your interviewer asked that how you want on the submission if you don't want to submit the form what you will do you have to say that we have to return false now the next narrow can be that there is a requirement data but from date is greater than the two days and what will happen okay so else if else if so in this section it is blank but in another scenario i can say that if it is not blank right so i will copy this and i'll mark it as not equals to blank and from day to date then it will not allow to submit the form but the error message could be this okay in this way we are done with this code on submit so express the scenario if requirement is blank then it will give us an error message in in case if the requirement is blank and the from date is greater than two two day then this code will get executed and the third scenario a requirement is not blank but the date given and the form date is greater than the two date then this will get executed okay so let's save it and let's navigate to the sr and click on here say reload so here on the form load the first requirement is fulfilled the second requirement requirement will get fulfilled on the change of this right i would be already download the same now if user is not selecting the requirement and he is clicking on order now see user is not able to submit the form it is giving him an error message okay so if user is selecting a laptop so if the user is giving a from date as 20 and the to date is 14 so it means two date is less than this from date and user click on order now see it is giving error message that formed value cannot be greater than enough to date is my user is not able to submit the form with if from that is greater than of to date okay so let's say if user is giving a correct date let's say it's 19 and now here i'm giving 28 and user click on order now see request has been submitted so friends in this way we can write a on summit client script on change client script and on load client script so friend this is basically a basic understanding of catalog client script so i believe now you can understand that when we have to write a on load when we have to write a on change and when we have to write up on submit client script after this video i will going to post a catalog ui policies concept that how that particular concept will work okay so friends if you have not subscribed my channel yet please do subscribe my channel and please provide your comment in a below comment box please like and share because your activities of liking sharing and commenting is basically a motivational kick for me thank you friends have a nice day bye bye please do not forget to subscribe my channel bye bye friends
Info
Channel: Basico ServiceNow Learning
Views: 8,992
Rating: undefined out of 5
Keywords: catalog client script examples servicenow, catalog client script onchange, catalog client scirpt onsubmit, catalog client script onload, onchange catalog client script servicenow, onsubmit catalog client script servicenow, onload catalog client script servicenow, servicenow catalog client script example, servicenow catalog client script get variable value, difference between client script and catalog client script in servicenow, types of catalog client script, udemy courses
Id: zkWTybCed34
Channel Id: undefined
Length: 21min 49sec (1309 seconds)
Published: Sun Jul 19 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.