#1 5 Use Cases of Client Scripts | ServiceNow Practical Use Cases

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] in order to subscribe to my channel please click here or click here please share comment and like my videos and channel hello guys welcome to sas word service now this is our new series servicenow practical use cases in this series we will talk about different practical use cases for different elements of service now like business rules client scripts glide ajax or other apis which we have in service now so starting with five use cases of client scripts scenario one the first scenario is if the caller of incident is vip user then urgency should automatically set to high and they should be an alert to the user creating the incident that the current caller is a vip user and the urgency has been set to high let me show you this requirement and the solution in my personal developer instance this is my personal developer instance in order to fulfill this requirement we have to first see that how exactly you can identify vip user so let me show you that first so for that we will go to user table so i will do sysuser.list you can also directly go to users module and you can see that i will bring vip field so there is a field on user table you have that vip field which can show whether the user is a vip or not so you will get that true or false value so you can see a lot of values are here so i can just filter this out to see how many vip users i have in my instance you can see as of now i just have one user so the requirement is if i go to incident and if i click on create new and if i select here a caller who is a vip user if the user is a vip user then urgency should automatically set to high and it should show an alert to the user who is creating the incident that hey the caller of this incident is a vip user and urgency has been set to automatically too high that kind of message you should show to the user who is creating the incident how can you achieve this particular functionality if you get this kind of functionality from your customer or clients you have to create a client script what i will do i will right click here and i will go to configure and then i will go to client scripts now this is a fresh instance we have not changed anything yet so i'm going to create my first custom script on this particular instance uh before that let me just capture these these changes in one of the update sets so for that i will just quickly enable application picker and update set picker in the header this is done you can see here and i will go to update sets so i'm going to create an update set so that i can capture all the changes i am doing and i can also uh put these scripts in the description section of of the video so here i will do let me client scripts demo demo and this is part of practical use case yeah i think that is puc so in that case i will do submit and make current that is what i will do so all the changes which i will do all the client scripts we will write today all for different five scenarios we have uh it will be captured in this particular update set so what i will do i will go to incident again so i will open the list and here i will go to client script now so i am going here i will go to client scripts so i will write the client scripts by clicking this new button it will open up the new client script form this is client script new record form so in that case i will provide a name first so we will provide the name set urgency as hi i will keep the table name as incident because that's what we have to create this client script for incident table ui type you can keep desktop in type now this is the one where you have to select as per the requirement you have now the requirement is whenever i will add that caller option that means caller will be displayed added over there in that case i will do on change so whenever i'm doing this on change and the field i have this color so i have selected the caller and now i have to write the script i will make this script field full screen and then i will start writing the script we don't have to write in this particular part because we are not going to do it for loading on load so we are just doing it for on change so i am going to start this script from here what i need to do because we need to get the detail of that caller field that and that is basically referencing that's a reference field where it is referencing to the user table now user table has that field vip because that's not on incident table so what you can do you can just write v v a r that you can create a variable and i can just maybe do vip alert and i can do equal to g score form now in this case i will use get reference now in order to get data from server on client there are various ways like for example get reference you can do it with the help of glide ajax you will see that as well and you can also do with the help of g underscore scratch bad if you're using get reference you have to make sure that you are using callback function in order to have asynchronous call so how exactly you can do that so i'm using this get reference method here you have to provide you can see the parameter it needed it needs the feed name and the callback function which are string so i will start with the field name so the field name is caller underscore id that's a name of backend name of our caller field here i will just do comma and then maybe i'll just give it a name a callback function that is vip function so semicolon and i whatever what i will do as of now that means i have i'm done with this get reference now i have to call this callback function so how i would do that i will just write function and i will do function vip function and i will do a bracket here and here i will give the variable which we created we will do vip and here i will i will give the condition now as you know the condition is if the vip is true if the user is vip and that how exactly you can identify with true or false value so in that case what you will do you will just write here a vip alert because you have already saved the value of this get reference here and then you can with the help of dot walking you can get the value of this particular uh this particular field this basically that's a table so that's how you can call all the fields of use this user table automatically when you are selecting this field here and get reference because you are referencing you are getting the reference of that particular field which will capture the value of that particular table and then i can do dot walking here so i will do vip alert and the name of the field is vip okay that's a name of the field in user table that is vip so i would do equal to equal to and i will make it true that's a true or false field and then i will write here because i have to set the value of urgency field so i will do g underscore form dot and how exactly you can set the value you can always set the value with this particular method that is g underscore form dot set value you have to select the field name you have to select the value you have to select the display value now as of now because this is a choice field so you can just directly uh you don't need to put the display value here so you can just mention field first that is urgency and if i do comma i can put the value that is the backend value of that choice hi choice so in that case that is one so i will do semicolon now this will definitely set the value but another feature we had that it it should also show a pop-up an alert how exactly it will do that for that we have to use alert function here and i will just use the caller of this incident is a vip user dot urgency has been set automatically to high so that's a method you can show to the user so in that case i will just click on save i don't think we have done any mistake and i can just click on save so our first client script is ready now we will test it whether we are getting the expected results or not how can you test it we will click on here and we will open up the new incident form and we will try to put that user who is who was a vip user so that jared user so let me just search for that user again i will just do sys user sys underscore user.list and i will filter it out and we will just copy the username so that i can select it on my incident form and i will select it it will show here i will select once i will select it you can see the caller of this incident is a vip user urgency has been set automatically too high if you will click on close you will see urgency has been set automatically on the client and now you can fill other details now this was the requirement and this is how you can achieve your requirement with the help of client scripts now this is just a demo this is just an example now you might get this kind of requirement not only just for incident form but for other maybe other tables as well or other forms as well maybe problem change request but but you can just use the same concept similar kind of requirement from your customer or clients scenario 2 if the short description contains infra keyword in the beginning then category should add a new choice infra and set it to the same now in this particular scenario if system will find infra keyword in the beginning of the short description then category should be automatically set and that's a new category choice that's called infra and that should automatically set as well so let me show you first that what exactly this requirement is in my personal developer instance so the requirement is for example if you will type here infra or maybe just type test short short description so in this case you can see it is infra is basically at the beginning so what it should do if i if i just change this value it should automatically add the new choice that is infra at the same time it should also set that value on the client automatically without before saving the form we have not saved it just on the client now if i will put this keyword maybe maybe here or maybe in between then it should not perform this functionality it should not uh change this category what we are talking about so the only condition is infra keyword should be in the beginning of short description so let's see how exactly you can achieve this functionality with the help of client script so i will go here and i will go to the list of incidents and i will directly go to client script i will go to configure client scripts here we will create a new client script you remember we created this one so maybe i will just click on update it so that we can sort that out the latest one we have created so this was the one which we just created and now i'm going to create second client script of this session new form is opened now i will provide a name so the name should be set category choice as high that's what name you can put ui type desktop now here type again we will do on change because whenever i will type that infra and if it is found in short description then it should change that category so we will do on change and it should be short description and now i will write the script so i will make it full screen and i will start writing the script now we are not going to do this in on loading so it should be on change and i will start with so in this case i don't have to use now that get reference because it is not a reference field first of all and that field is already available on the client so in that case what i will do first i will capture the value of the short description which which i can do with the creating the variable like just short underscore d and how can i get that value so you have to remember this is the method i'm going to use g underscore form and that's the api all the api we have for g underscore form and if i do get value and i press tab it will automatically show me that this is the method which you can use to get the value of any field any field on the client with the help of g underscore form dot get value you have to put the name of the field here so that will be short underscore and that's a backend name description and i will do semicolon here and now i have to the requirement is that you have to search that word in the beginning if that word is in the beginning then only you have to change the category else not how can you get that position now in order to get that position you have some some functions in in javascript as well so for that i will just quickly show you i will just write where position and i will do short because that's a name of the field the value here which we're getting from uh from that particular field so i will do short underscore d and i will do dot search now this is the function now here you have to put the word so the word which we are talking about that is infra the keyword which we which which will be found or which will be surged in short description so here we have now i will uh give the condition that if position now what this position will hold this position variable will hold basically the position of this infra infra keyword in that short description and if that keyword position is equal to equal to zero if it is zero that means it is at the beginning that's how you use this search function so in that case i will what i will do because if it is found in the beginning so what it has to do it has to do g underscore form i have to set the value how you do that for that you have a method that is add option here you have to provide a field name that is string so these are the parameters basically field name choice value choice label how we will do that so i will do category that is the name of the field backend name i have to provide the choice value that is the backend name again of our new choice val choice choice like new option and then i will provide maybe the label name now so i will keep maybe i as capital in in capital letter and then i also need to set it so as of now i'm just adding the option but now i'm also setting that value maybe before setting it let me show you how exactly it works then i will come here and just show you that what is what is the use of set value again what is the difference you will find when you have just add option and when you do this set value so maybe i'm not using it for now and i am just saving it so my new new client script second client script is saved and what i will do i will come here and i will reload it and i will type here infra test if i change this now you must have seen some changes but not on category field let me show you that you can see that at infra choice has been added but it is not set yet how exactly we will do that so i will go to my client script again i will come here and i will do g underscore form dot set value and here i will do category and i can just put the backend name of our new choice that's it and i will just save it this is saved and if i come here let me reload it and if i type infra and i type test and if i just select it you will see that category has been set to infra choice now if i maybe for example let me just reload the form i will put this infra keyword after test so we will write test and i will do infra let's see if it works or not you can see that it is not pushing that value you're not getting that new choice as well that means your requirement has been fulfilled and this it is setting that category twice when when that infra keyword is coming in the beginning of short description so this is how you can fulfill the requirement you can you can utilize ad option method you can utilize set value as well and a new javascript function which we also learned that is search if you want to search the position of any particular keyword in any any string any string field and you also learned about g underscore form dot get value so that you can get the value of that particular field on the client with the help of g underscore form dot get get value gender score form dot get value scenario 3 when user opens the existing incident and the priority of the incident is p1 then there should be a message at the top that the current incident is a p1 incident how can you achieve this functionality so i will go to my personal developer instance and i will just close this incident here and what i will show you let me just open any critical incident so the requirement is if i open any any critical incident that means the priority is critical priority is one and whenever i will open that there should be a message at the top that this incident is a p1 incident the current incident which you are opening is a p1 incident that kind of message we want to show that means you have a requirement that user should see on incident form so in that case you have to write again a client script so i will go to client script and here is our third client script which we are going to create for this requirement for scenario three so these are two two other uh client scripts which we created and here is our third one which we are going to create so new form is open so i will just give a name maybe show p1 message so i will just provide the name here ui type now this time as of now we were selecting on change now this time we have to select on load because the reason behind it okay that's a requirement whenever user opens that means loads the critical critical incident then only i should be able to see that method the user should be able to see that method so in that case i will select onload and i will go come to our script field i will make it full screen and i will start writing the script it should be pretty much straightforward so i will just first get the value of the priority field so i will do where priority equal to g underscore form dot get value because you have to get that value of that priority field so this is the backend name of priority now don't get confused that i'm using priority and pride this is just a variable which you are using maybe let me just maybe i can just use priority value i think that's what i will take so that it is clear to you you don't have to confuse that this is same thing this this priority is the field name the back end field name of our incident uh form or of our priority field of incident form and this is just a variable because i want to capture the value of priority field because i have to use that value in here i can just put if priority value equal to equal to and that's a backend value one and i just do like this curly braces here i have to add that message how can you do that you just need to type g underscore form and you can do dot add you will see here add error message add info message now info method will show you the message in green but this is something critical this is something you want user to focus on so in that case you will use error method that will show uh in red color that message will be displayed in red color so i will select add error message and the message i will type the current the current incident is a priority one incident that's it and i think you can put the message as you want as per your business requirement so i will just put semicolon here uh i think we forgot to put semicolon here as well uh priority value priority value i will just see if everything is good this is for alignment of your skips i will just format the code and i will save it so your third client script is ready that's show p1 message so now i will do a testing i will open any existing p1 incident so let's open a non-p1 incident maybe this one first we will see whether we are getting that message or not you can see we're not getting any message because this is not a priority one incident but if i go back if i open any priority one maybe let's open this one and let's see yep you can see that we are getting that message the current incident is a priority one incident and as i mentioned this is also in red color if you will do that info message you will get this this particular message in green color because it's a priority one it's a critical thing to be focused on in that case you should definitely use uh error message rather than uh info message scenario four when user opens the existing incident and there is a parent incident of the same incident then there should be a message at the top this incident is a child of current incident the number and when user clicks on parent incident number it should open the same in incident in a new tab now you would think that we are talking about the same kind of requirement showing a message but this is totally different yes it will show a message but the requirements slight different let me show you first so if i go to my incident form here now the the requirement is that if the incident the requirement is that if incident has a parent incident then it should show at that method over here also with the parent incident number and there should be a hyperlink on that number and if i click that number it should open the same incident number in a new tab and you can think of it's a totally different requirement what we were talking about earlier but that was just like this requirement this is just a simple message so in that case what exactly i need to do first we will talk about that how exactly you can identify which one is your parent incident record so in that case uh here you can see we have this field parent incident now this is out of the box so you have this parent incident field here now if this incident has a parent you will see here so let me maybe show you the list of incident and we will bring that parent incident in our list in our list view so that we can check where exactly uh like what fields we have parent record uh updated so you can see i will filter this empty out so we have this one one incident where we have this parent that means this one is parent and this one is child and this particular the child incident should show that message that hey that current incident is child of this incident and this incident should be in hyperlink so that i can click on it it should open the same incident in a new tab so let's see how exactly you can achieve this particular functionality so for that i have to write a client script so i will go here and i will click on configure and i will click on client scripts so as of now we have created three custom client scripts as of now now we will create fourth one for this fourth scenario here's our new form of client script so i will just start with show message for parent i think this kind of name you can give i think you should always give names to your different scripts or whatever elements you create in service now you have to make sure that you are you are given the right name so that other developers can identify that what kind of different scripts you have created so they can also identify for what functionality you have created these client scripts so i will just do show message for parent now in this case we have to get the value of parent and how exactly i will achieve it we will still use get reference which we used earlier so let me start with the script uh before that we have to select the type as well now type should be because this is this is something uh you if you load the incident form so again you don't have to select on change you have to select on load and if you select it you can start writing the script but let me just make it full screen so let's start with the script now in this case to fulfill this requirement you have to check whether parent field is empty or not if it is not empty then there should be a message on the top of the incident form however however you also know that we have some extra requirement where that incident number should be hyperlink and it should show the number at the same time if i click on that number it should also open that particular url open that incident uh record in a new tab how can you achieve this for that what we will do we will start with uh let's see we will do parent i will just write this one maybe i will just do parent and i will do i will first get the reference value of that particular field so maybe i will do get reference gender score form get reference and here i will put parent underscore incident that's the name of the field that's a backend name of the field and then here i will give the callback function as i mentioned earlier whenever you are using get reference you have to make sure that you are using callback function so in that case i will maybe use parent function that's just a callback function name i'm using semicolon and i will just declare this function so i'm going to declare it and here i have a parent function function and i can give this particular parameter here and i will start with this function and i will write here you can do p so you have to get the value of that particular parent field because if it is if it is not blank then only you have to show that alert message so in that case what i will do i will get the value first so i will do g underscore form dot get value and here i will do parent underscore incident and then i will do if p the value p if not equal to blank that's how you can you can give this value if not blank so in that case then it should show that alert message now i can make that alert message with the help of add error message i can do that but as i told you it's a custom thing which we have to make we have to make it hyperlink how can you do that so i will start writing it first that current incident is a child off here you should have your number but that should be hyperlink for that you have to add html reference that is a a you use that tag in html to make anything hyperlink so i will put it like this i will do plus and now i have to write another thing here i will start with a because that's a reference a tag to create anything to make anything hyperlink in html so i will do h r e f equal to now here we have to add the url the url for incident how can you get that url so for that let's open any random racket so we will open any random racket let's say this one so if you have these incidents just right click here you will get this url to key clipboard just copy this come here and what you can do because you have to make that particular url so that you can display that particular data to your user so in that case i will do href now this href again should be in quotations so i will paste here but you will see the information that it is populating the ussid that means you have to make this society dynamic as per the society which you are getting from your form so in that case what i will do i will remove this now one more thing you have to do because it is it you have uh these um quotations that is something you have here so let me let me check this first i will do um then what i will do i will put here this and i will make it like this so now here is the string and i have to add this quotation as well for that you you have one basically you it's you have to escape characters you have to escape the character that's a that's kind of feature you have uh you have to mention in javascript whenever you have to create a string so in that case and you have a quotation as well so in that case you have to do this wherever you have this quotation in this string and i think you have this here as well so i will do this so forward slash and i have society equal to uh i think as of now i i can't add this one so let me don't add this one um i will just do says id equal to um let me just do that uh you don't have to do here because you still need to add that cis id so as of now you can just do like this that's it and now again plus because we have to add that society so how exactly we will do that we will utilize that that particular racket which we have used this payment and we will dot walk we will get the information we will get the society because that's something we have to push in the url and we will also get the number so in that case is child off and i will do here plus parent dot cis underscore id that's a ssid of our of our incident record which is in that particular field and then i will do plus and i have to add that particular particular option again so maybe i will just do single quotation and this time i have to select that option so i have to close that so you can close like this but as you know because we have to uh basically close that hyperlink this href as well so for that i will put one more quotation and i will just do this if if i will do that i will automatically i will just close this here and now i can just do plus and i can give the number now because i have to display in that href label the label should be the number how exactly we can do that you will write parent dot number you will do dot walking again and i will do plus and now i will close that link the link tag we have that a tag and i will do like this and i will do slash a it will close that html tag and that's it but the one thing you have to remember you have to open this a new tab in order to open this a new tab there's another html tag you have to mention uh that is something target equal to underscore blank how can you do that let me add that as well i will come here and i will do target equal to again quotations i will type underscore blank so here i will do again this one and i will mention here as well so we are doing this uh backslash and then in that case i think this is done you can see we're not seeing any kind of different of difference of colors so the whole is a string now and it will be able to take this value i think we are done we don't have to write anything else so i will just click on save let's see what happens so your fourth client script is also created let's see the results so this time i will try to open this particular field where we have this parent incident so i will click here if it opens incident record you can see that current incident is a child of this so it is showing the parent incident number and if i click it you will see it is opening the same record and new tab and that's really awesome guys i think you have you have been able to achieve this requirement as well so you can see we are able and the same incident is a p1 and you can see the old message which we populated in our different scenario this is how you can achieve this kind of requirement when you have this kind of scenario in different use cases you have from your customers and clients scenario 5 whenever server class ci is selected in configuration item field on incident form then description should be auto populated with the details of ci that is asset tag company operating system and os version so let's take a look and let's see in my personal developer instance that how exactly you can achieve this functionality so what i will do i will go to my incident form now the requirement is whenever i am trying to create a new incident for example and i am selecting a configuration item here system should automatically check that if the ci selected is a server class ci if that's a server class ci and it should automatically populate some of the details here which we just saw but before starting with the requirement before creating the script client script let me first show you the cis we have so if i go to configuration in the left hand side if i go to configuration i will show you those cis which what kind of ci's we are talking about so here is our configuration module application and if i go to this section the server all so these are all server cis we have you can see that so maybe i open the first one application server help desk this is one of the server and the class is cmdb uh cmdb underscores uh cmdb underscore ci underscore server that's a class name uh so this is how now these are the details like you have to you have asset tag you have company you have operating system and you also have os version os version is blank right now so maybe i can just put maybe okay maybe two maybe i will just put maybe maybe 1.2 i'm just putting it randomly so that i can show you this example otherwise uh it will show null value so that particular data will be empty if i would not have anything anything here so i will start with showing you we have the ci so we will select this yeah let's let's keep it simple so we will use this this particular ci now the condition is as i mentioned whenever i will select that configuration item on incident form it should automatically populate these details now the name we have back in name like we have asset underscore tab we have we have a company we have operating system as os and we have os version as os underscore version so these are backend name which we have to use in our script now how exactly you can achieve this requirement now this time we're not going to use get reference we are going to use glide ajax so in this case you will be able to learn glide ajax as well that how exactly you can utilize glide ajax when you will get your requirement from your customers when you have to show something from server side data to on the client that how exactly you can utilize glide ajax so let me start with this now for glide ajax you have to create two things one is script include that is also client callable and another is client script that's how you can fetch that data and show and do anything as per your requirement so let me start with script include first so i will just go to script include application we have this module we have here at script include and i will click on create new so i will just create new script include i will give it a name so maybe i can just give it a name name should be maybe i will just do inc and i will do function it's just a normal um i think name i'm giving to my script include i press tab it will automatically select the api name as well now i will start writing this script but as of now i have not made it client callable so i have to make it client callable so whenever you want to call any script any script include from the client you have to make it client callable so i will select it you can see this has also changed in that case i have to create a function first so maybe i will start with get ci details and i will do semi this colon and i will do function brackets and i will start with my script now now what exactly we have to do because this script will help you to return the data to your client the details of all of your server data you will store here and send it back to your client how will you send it how will it get for the first you have to get the server data so for that we will do a glide record var gr we will create a variable for glide record variable so i will do new glide record here i will provide the incident table name i'm sorry i think here you will provide the name of your ci now you have to select you have to check whether that ci is a server class ci no server class ci is definitely a table in service now that's how cmdb is designed it is a table which is extended from cmdb underscore ci so what you need to do rather than cmdb underscore ci you should directly glide record on cmdb underscore ci underscore server that's a class name of your server cis so in that case i will do a glide record here and i will do gr dot add query so we will do add query what exactly you have to check that you have to check the society if that society is found or not in your cmdbci server class if that society is found that record is found which is selected on the client that means it is a server class ci but that's how you have select you have to check the society i would do comma you have to get that value so i will first create that parameter so you have to do always get the parameter first so you will do get para meter now here you have to just create a parameter what parameter let me just maybe just give a random sperm underscore ci now this parameter will be sent from client how we will send it i will show you quickly that's our next step to create the client script which we will send from client script so i will just select it here and i will do gr dot query we will just just query the table now so if that css id is found so i will do gr dot next if that is found then if if that particular ci is found that means it is of a cmdb uh ci server class name that means that's that's that the class of that ci which you have selected is a server class in that case you can just directly do gr.next and you can just populate the data the data you have to send it to back to your client what data same data as a tag company operating system and os version now you have to populate that data in a really good good manner not just a random string so what you can do you can still use kind of html here in the string how we will do that so we will just create a variable and i will just put it maybe details that's the details we have to populate over there and i will write i will start with creating the string like asset tag colon give a space plus now here i will have to populate asset tag so i will do gr dot asset underscore tag i will do plus again now here i don't want to put that value the next value in the same line for that what i will do i will do a next line this is the html one which i'm doing so i will do for the string i'm doing this next line and then i will maybe select company colon give a space here and i will do plus and here i will do again gr dot company company plus again we have to do next line so i will do next line you can also do one thing maybe you can just give a space and then you can just write the next next detail you want to provide that is operating system i will do space here and then i will do gr dot os then plus i will do slash n and i can just provide os version colon and i will just do plus gs dot os underscore version and i will just do semicolon now we will just do return because we have to return so that's what this function will return this data and we will do details that's it you are done you are done with the script include it is just giving the error the reason behind it because you have to add this is comma you're done you're done with the script include i will save this so now i have saved this script include next step is i have to create a client script i will go here and i will maybe go to incident list and i will click on here go to client scripts and i will create a new client script that's our fifth client script for today but overall we created i think six clients uh six scripts five client scripts and one script include so i'm going to create fifth client script now now you have created that script include now we were talking about glide ajax so that glide ajax now we have to declare in this client script so that we can call that script include get the data and show it on your client that means you have to push that data into your form incident form so how we will do that so let me just give it a name name first so that's something i can do set ci details maybe i will just put set server ci details that's the name i have given uh i will do on change and whenever i'm selecting that ci so maybe i will do configuration item here here i have unchanged script i will make it full screen and i will write my script so i have to declare that declare that particular uh glide ajax how exactly we can do that and that's how you declare glide ajax so you will start with ga equal to new glide ajax like you use glide racket here you have to use glide ajax now here after glide ajax in these in these brackets you have to provide the script include name which you have created here so you will just copy here go over there and select that's it then you will do ga dot now you have to call that function which you have created because you can create multiple function in a script include even in your server side script include even the client call label so here if you have add params you will do add param and you have to call that function so for that you have to do sperm name that's how it's a default uh syntax of calling your glide ejects so here i'm i'm going to call that function and that function let me just check first this is the function we have used i will copy this i will copy the function so that it can get that value and we will do g ga dot add param again now because we have used that parameter because that's how you run this glide ajax because the parameter is the one which will get the value save that save that value in that parameter and then push your client script that's how you do so here what i will do i will do sperm name same name which you have selected over there says sperm underscore ci and then i will do comma here i will do g underscore form because i have to get that value value of that ci what and how when you will do that whenever you do this get value for your reference field it will get the store basically society of that reference field in this case it will show the society of the configuration item selected so i will do get value and the field name we have is cmdb underscore ci semicolon and now i will do g now here is the tweak you can do get xml weight you can do get xml but we always need to do glit xml so that you can have asynchronous call you cannot have you should not do a synchronous call you should always do asynchronous calls in that case i will select get xml and here i have to select the function so what function i will do maybe i will just uh maybe i will do show show i will do details that's what i have to use i have to show the details and now here i will declare that function i will create that function here i'm just doing show details i will put that value basically here the response so i will do response and this is something the default one that's how you uh create whenever you this is the syntax of glide ajax so i would say function show details response and here you have to do where answer now you have to save that value the response which you will get from your script include whatever response it is returning that you have to save it in your answer variable how we do that you have to type response dot response i think xml it's on caps dot document you have to remember i think sometimes i forget so you have to remember this you have to write a document element that means you have to get habit i think if you will keep on writing a script include and glide ajax i think it will be really easy for you so you can just do get attributes and here i will just put get answer here is the attribute we have to select answer now we have get that value in answer variable now you have to push that value how we can do that as you know for pushing we use set value so i will just go to set value select the field that is description field description and i will just put comma and i will just mention here answer now this is the variable this one which is basically saving that value and i mentioned semicolon and i think i'm done i think i don't have to put anything else so we are done with this client script it would be able to call our script include that is client callable and pull the data and populate it in the short description so let's do a test now i will go to this incident form here you can see that configuration item is not selected now what exactly it will do it will update the description it will add those details so it will directly populate it it will remove the data because you have not uh you have not added the current data which you have in description it will just replace this data so i will just uh select it same ci where we have that information that's a server class ci if i select this you will see oh it's not working so maybe we have some issue with our script let me check the script first so and this is how you can do debugging as well if you're not getting expected results you can just check the syntax because i'm sure there should be some syntax issue with my script so let me check show details uh answer response that looks good and get attributes okay so here is the issue this should be get attribute that's the syntax you have to use in glide ajax because you're calling this function so it has to be get attribute not attributes your s should not be there so i will save it let's see if i get that data so i will go here i will reload it and i will try to change the configuration item again which is of server class so maybe i will select the same one um i will select this time let's see okay we got it you can see we have we have this data populated in description field now this is not saved yet you have no you have saved that data yet it is just populating on the client once you will save this data then then this data will be saved in your incident record but as of now it is just showing on the client so this is how you can you can write client scripts for different requirements for different use cases for your different customers and clients i hope this this video will be really useful for you in your practical practical implementation whenever you have to use or you will get this kind of requirement you can you utilize and create client scripts like this whatever uh apis whatever methods whatever functions we used in our client scripts so please like share comment on my video if you have any feedback please comment i will definitely work on it so thanks for watching my video have a great day
Info
Channel: SAASWITHSERVICENOW
Views: 13,268
Rating: 4.9817352 out of 5
Keywords: incident management, incident, What Is ServiceNow, what is servicenow platform, servicenow training, servicenow administrator training, servicenow tutorial, servicenow tutorial for beginners, what is servicenow software, what is servicenow administrator, servicenow basics, ServiceNow Architecture, ServiceNow versions, ServiceNow Platform, introduction to servicenow, servicenow, servicenow client script, client scripts in servicenow, saaswithservicenow
Id: wM128lO6cbY
Channel Id: undefined
Length: 57min 33sec (3453 seconds)
Published: Fri Jul 24 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.