[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 hey guys this is gaurav welcome to sas with servicenow this is my first video for servicenow developer training in this training we will talk about how to perform scripting in servicenow so if you want to become a servicenow developer now this is the right place and right video i will be posting multiple videos on the multiple topics as example client scripts ui policies business rules skipped includes workflows glide ajax these are all the major topics which will make you a good developer if developer will learn these topics these functionalities of servicenow then you can become a good developer and you can all you can see what exactly i have written let's learn servicenow coding so let's begin with the training before that let me tell you something about myself so my name is gaurav tripati i have around 9.5 years of experience in it i have around 6.5 years of experience in servicenow architects solutions and project delivery the picture you are seeing on the screen it is from the knowledge 2018 when i was in knowledge conference so let's let's start with the the training prerequisite now if you want to learn this particular training and if you want to attend this servicenow developer training then there are some prerequisite if you fulfill these points then only you should watch these videos you should see this particular training the first criteria is you should have at least six months of experience in servicenow administration so maybe you have worked in your organization maybe you have worked personally at your home you should have at least six months so that you have an idea how servicenow platform works what are the different admin functionalities you can work upon in service now second criteria and prerequisite prerequisite is you should have knowledge of javascript and that's a really important uh criteria for this particular training because we are talking about coding we are talking about scripting now in order to do dev uh development in order to do coding in service now you should have proper knowledge of javascript so if you know javascript that's really good however the third criteria i have mentioned here it's you should be completed code academy javascript course now this is the first step which i took myself when i started scripting in servicenow and i would say this is a really important step i used to do little bit coding in service now however i didn't have much practical experience in the beginning so one of my mentor one of my colleague suggested that before starting doing the scripting let's complete this course first then you can switch to scripting and i can tell you with my practical experience that i was able to succeed when i completed its complete javascript course then i understood okay and i was able to do proper coding in servicenow but if you're already working in a javascript project in your organization or you are doing some of the javascript work in your error in your personal work then you don't need to do that if you're confident that yes you have proper knowledge of javascript then you don't need to do that but any person any developer who or any person who wants to learn development and he's new to the system new to the development world then he should definitely complete this code academy course how this training will help you you will be able to do scripting in servicenow so once you are done with this training you will be able to do scripting in servicenow you will become a servicenow developer you can develop solutions and service now you can customize your instance with additional functionalities so if you will learn or if you will watch this training then if in your organization you get some new requirement which needs some coding some scripting and service now apart from configuration then you can definitely develop those solutions in service now after watching this training preparation for scripting so this particular topic i mentioned like for this training our first topic would be preparation for scripting we will learn that how exactly you can do uh scripting and service now but before doing that scripting what are the prerequisite i'm not talking about the criterias it's just a prerequisite or just you can say it's kind of a baseline that you need to understand to prepare yourself for scripting what are we going to learn in this particular section and video we are going to talk about what is scripting in service now when to script that means when exactly you need to do scripting in service now where to script where exactly you have to write these codes and then type of scripts that what are the different type of scripts you write in service now this is what you're going to learn in this particular section servicenow scripting scripting can be done in servicenow to customize the instance with javascript servicenow provides classes and methods which can be used to enhance and customize the platform functionality now in order to do customization in service now you can do it with the help of scripting service now also has its own library and it has developed some kind of classes and methods which you can call them in your scripting and then you can customize the platform and i would say it has given you some kind of easiness so that you can build you can build your solution without any issues so if even if you know little bit about javascript code you're not expert you can still do coding in service now so i just want to give you confidence that any person who is not confident about even after completion of code academy course if you're still not confident and you still know i would say basic of javascript where you can just write a small code you can still learn servicenow scripting and i can tell you because i was not in encoding world in the beginning but i learned it and i i showed myself so i can tell you the i can i can give you the confidence so the people who are watching this video who have never done coding in their life don't hesitate you can still do the coding now the javascript used in service now is based on mozilla rhino mozilla rhino it's it's a different framework where it they came up it's totally dependent on the ecma that's a that's i think it's an organization who has uh like supported this javascript with the version four five i think currently five is going on so javascript used in servicenow is based on mozilla rhino you i would i would recommend if you can just do google and then just search for this mozilla rhino you will be able to learn you can also learn javascript directly from there so the javascript which is used in servicenow is based on mozilla rhino when to script and service now now when exactly a developer or administrator should think that he should perform scripting in service now so the conditions are need addition to out-of-the-box functionality so if any functionality is you're not able to get that solution with the help of out-of-the-box then you have to write a script need integration with other application when you have to integrate service now with other third-party applications then you have to write a script need to do automation if you want to perform some automation in service now maybe some running some workflows then you have to script end service now you should do scripting now these are some examples which are showing when exactly you should do scripting so you should do scripting to show an alert if field value changes and push the value of a reference field value so if you are on an incident form and you want to push some value on any field and you also want to show an alert then you might need to do some scripting if you want to copy comments from parent incident to child incident then you have to do scripting if you don't resolve the incident if child tasks are open that means if child incidents are open and you don't want to resolve parent incident then you have to do some scripting where you have to do those scripting we will talk about it later as per the situations as per the requirements show assignment group values as per the assignment groups so you have assignment group values as per the assignment groups so on incident form if you have assignment group or you have assignee and you want to show some values as per the assignment group you can do that push the field value on change of other field value so you are changing one field maybe a category field and you want to change the assignment group you can do that in in that condition you should do scripting now out of those examples or out of any of examples it might happen that not every time that you have to do scripting because those are the things can also be fulfilled with the help of just out of the box functionalities you should not do scripting now these are some examples when you should not do scripting in service now make a field read only when you want to make a field read only so we already have a ui policy functionality where you don't need to write a script you can do it with the configuration change hide a field when form loads when you want to hide a field when form is loading then you don't need to do that you can write a ui policy again set the value of a field when assigning group changes you can do it you can achieve it with the help of business rule so we if you want to set any value on the field when assignment group changes then you can also achieve this with the help of a business rule configuration you don't need to write any kind of script so these are just examples that when you should not do scripting and as i mentioned earlier in service now there are multiple situations when you don't need to write scripting you can directly achieve those solutions achieve those requirements with the help of configurations and you don't need to write any kind of script but you have to learn scripting because you might get some of the requirement which cannot be fulfilled with the help of out-of-the-box solutions so you have to write the script and you have to provide the solution where to script in service now now in order to do scripting and service now where exactly you write these codes servicenow provides a script editor in servicenow you will find a data type of a field as well called script where you can write the code so you can see as is mentioned servicenow provides script editor which can be added a field on any form and script can be written in the field i will show you in little bit the javascript is written in this script editor the kind of script we have is like this on the screen you can see uh there's a blue box and it's kind of a script editor so let's take a look what is this script field and what is this script editor so let's take a look on my personal developer instance this is my personal developer instance and i will show you where exactly we have that script field so if i go to maybe ui policy and i click on ui policies and if i click on this one okay uh as of now it is not showing you uh the script field in order to get that field you have to click on this advanced view on ui policy form so if i clicked on that then i will get that advanced view and i will also see the script field you can see this is the script field if i click it i think form is not loaded yet yep now it's loaded so if i click here and if i click on run script you can see this is the script field so this one and this one if i right click here this is and if i show you configure dictionary and so as i mentioned earlier if you remember i mentioned where you write the script the script type the type of the field would be a script that is the one and if you see and if i click this list and you must have read it in your servicenow administration training so these are the type of fields we have and in this type we also have a script so we have one is a script and one is a script plane so you can utilize both so this is the script editor where you write the script types of scripting now how many types of script we have in service now so let's take a look we have client-side scripting we have server-side scripting and the third one we have it's mid server scripting you must have read something about mid servers in your administration codes now these are the three types of scripting in service now client side is anything which you want to see on your browser which you want to load on your ui that will be your client side if you want to customize something some play something around like showing the feed values hiding the field values everything is on client side because that is being loaded on your browser when it comes to server side if you want to sub fetch some value from the database if you want to uh play with your data you want to change the data you want to fetch the data update the data that is all related to server side even on the form if you want to push some value from your client to your server then if you need some calculations maybe that happens at server side and that is called server side client uh script not client script server side script and the last one is mid server so if you want to integrate your service now with other applications then you have to do your mid server scripting in that case so these are the three types of scripting in service now client side scripting now what are the examples of client side scripting so in client sign scripting we have ajax client scripts ui policy service catalog ui policy the ui policy it runs at browser right it runs on the client end that's the reason it's a client side scripting client scripts ui actions ui context menus validation scripts these are all you want to put some validations those are all client-side scripting then you have server side scripting server-side scripting and you have like access control list like acls you create acls you put some access level those are all server and not at client end ajax server scripts when you have to calculate something or you're you're getting some function call then you you write script include that is ajax server script when you write the server script from the script include that is the server and script so for example if you want to um if you want to do something on a client but that needs some server side scripting as well so you write two kind of scripting over there one you write on client side because you have to call that script include where you have written the function and on that function which you're writing that is the server side code then you have business tools business tools they are used to update the data change the data insert the data those are all server side scripting then script actions script includes transform map ui context menus workflow editor ui actions these are all server side scripting glide class overview now servicenow provides javascript classes exposed by glide you can work with the table using scripts with the help of these api so servicenow provides you some kind of a javascript classes you can call them and just just do whatever operations you want to do they're like in-built classes they have already developed they have provided you the classes which utilize them with the help of methods and just call those methods and you can run your script you can perform database operations with these glide apis so you can perform for example glide record glide record is is a kind of glide where you can do the your database operations you can fetch the data you can insert the data you can change the data whatever you want to do you can do this with the glide apis glide classes in light classes we have two type of classes one is server-side glide classes as i mentioned glide racket underwater is glide client-side light classes that is the second one so there are two glide classes server side client side server side glide class now what is this what are these server side like class we have like glide racket which i just mentioned glide element glide date time so service now has already built in some functions to honor to use for date time as well glide aggregate if you want to uh like count some of the rackets you can you utilize this glide aggregate you don't need to use glide racket then if you just want to count the records aggregate and then you have glide system these are all server-side glide classes client-side glide class client-side lights classes we have glide ajax glide user glide menu glide list 2 glide form and glide dialog window these are all server side glide class so now you got the difference and what are those classes in server and client side glide script execution engine now this is one of the important i would say a factor of scripting basically because so that you can understand as you have seen that we will have multiple type of scripting in service now we will have business rules ui policies client scripts there's a lot of scripting in service now now if you have written some piece of code in every area which one would run first because when you will head to the system and you will enter into the system what will what kind of script will run first and this is really important to know uh i can tell you that this was one of my question in in my interview in in when i was giving a interview in one of the company i got the same question as well so this and that's the reason i have also added as an important topic to learn scripting and this is all you will also if you will see servicenow documentation this is also mentioned over there so just check it so as of i think i have not mentioned every part of the complete execution engine but you i will mention the link in my description and you can just watch that and you can see that how exactly the order of that script execution works so if i if i talk about it before business rule with order less than thousand it runs first then before engine for example approvals data policy field normalization workflow then before business would with order more than thousand database operations then insert update delete after business rule with order less than thousand after engines table notifications engine update sync engine email notification it is this kind of order of script execution in one go and then after business rule with order more than 1000 it's like a single table we have and you have written multiple scripts you have notifications you have workflows everything approvals data policy what other things will run first that's how you can learn from here syntax editor we just talked about the syntax editor that where exactly you can write this script that is your syntax editor script editor servicenow provides support to write javascript in syntax editor it has features like syntax coloring keyword search automatic closure of braces code assistance it also give you the code assistance as well when you write the code if if you are writing the code correctly it will give you what can what what exactly you can write next that's the code assistance we have like you must have seen a lot of ides you have maybe in java dotnet anywhere it's it's quite similar then you have script macros can be used in the editor we will learn about script macros later it's kind of predefined scripting where you can just mention and it will automatically give you the syntax with just one word at the bottom you can see this is the script editor syntax editor and you can see some of the options and buttons at the top we will learn about these buttons as well syntax coloring now this is the really important thing to know when you will write the script you should know uh what color shows what functionality what kind of syntax it is it is telling you so you can see at the top we have comments in green so this is a comment if that is if anything is in green that means it's a it's a comment and we have already started with uh slash slash that is converting it to comment and converting it to a green color javascript commands in purple wherever wherever you have this javascript commands and system knows that it is a javascript command it will automatically convert into purple so that you will know okay if you will read lot of lines in the scripting you will come to know okay this particular thing is a javascript command strings in blue so when you have script blinds and if you see anything in blue as you can see on the screen that this is a string in blue that is your strings it's not something directly in the javascript it's just a coloring if you have anything in the screen strings in in braces you have this blue color syntax editor functionalities as i mentioned earlier that you have these buttons at the top now they have their own individual response functionalities basically and act in a different way so let's talk let's talk about what are these functionalities of these different buttons we have at the top of the script editor one is enable disable syntax highlighting so you can also see without these colors and all it will just a script editor that's it it will not show you these options it will not show you any kind of coloring that's a plain editor like a text editor so you can enable and disable with this particular button toggle comment if if you have a piece of code and you want to convert it into comment you can do it directly from here select that particular uh code and just click on this button it will automatically it will add those slashes in front of those lines so they will automatically be converted into comment that's that's how this functionality works then we have format the code if you have written multiple line of code and it is not in a formatted way if you click this button it will automatically format it as per your code maybe if else these kind of things it will automatically format it replace is something if you want to replace for example you found a word and it is mentioned everywhere in your script in the complete script editor then you want to replace that word then you can do it with this particular button and it will replace once next is replace all if you have a word it's everywhere maybe it's it's maybe 10 times repeating in in your complete code in syntax editor and you want to replace every word with that particular name you can do it with this functionality click it mention the word replace with and done search if you want to search something if you have a very big code you want to search for any word you can directly do it from here idly i do sometimes from browser like a browser has its own find i do it from there but you can also do it directly from here maybe it is more i would say better solution find next as i mentioned when you find something you can click just find next next as we have in i think in our word as well or notepad as well it's it's quite similar functionality find previous this is full of screen if you are writing the code if you are doing this coding and like you want to make it in the full screen then you can do it so it will when you will click this button it will automatically make your script editor as full screen this is help it is just kind of a shortcuts it will show you like what are the shortcuts we have for these functionalities maybe save or some other functionalities you can do it with the help of help i normally don't use it but it depends on the users or developers if you want to use it you can directly do it from here then we have save button so either you save that complete form where you it will also save this script field or you do it from here it's same there is no difference it's just an additional functionality you can directly do it from here rather than doing it from the form then you have syntax check if you will click this button it will try to analyze and screen your codes and check for any syntax error it is very useful so i always keep it open enabled so you should also enable it so that it can check your syntax and the last functionality we have is script debugger now we didn't have debugger functionality in servicenow before we did have it with some different ways but now a scripted debugger we didn't have anything like that but now servicenow have recently introduced this functionality i'm not sure maybe it was in london or kingston but it was introduced it's a really good functionality you can do the break as well that's a major thing and i think it's a really good functionality i i think i have rarely used it but if you want to use it you can definitely use it so it's really good for good coders who who have really big like big multiple lines of codes you can use it with this script debugger syntax editor macros we just talked about these macros and these are kind of a help which gives you the syntax automatically you can also create it and we also have inbuilt as of now a few of them from servers now out of the box so script editor macros macros provides shortcut for commonly used scripts it can be inserted in script editor with a text saved in macros let's take a look in my personal developer instance so you need to search macros now don't get confused because you will find ui macros they are different they have different functionalities they are related to ui and the one which we are talking about right now those are syntax editor macros and that's the reason service now has written over here syntax editor macros if i click here and you can see these are out of the box let's let's check one of them as an example where gr now this is where gr out of the box macro you can also develop it you can also create it if you want because if i go back it gives me a new button and i can do it it's editor macros and if i click here and you can see i have this one where gr it is giving me the complete syntax so if you have any syntax which you utilize every day maybe every week you can do it you can do it you can also create it for your complete team if there is any syntax which is used every day maybe or every week for a developer you can do it directly from here now how exactly we we do it i will show you in this accepting field let me show you so i go to one of the business rule maybe and i will click new it is still loading okay skip field is not enabled i will go to advanced i will go here and i will where g are done so you saw that i did not write all the codes so what i did i will show you again i just wrote the same keyword which is mentioned in the syntax editor macros i just went here typed where gr and i press the tab on my keyboard when i press the tab it will automatically show me the complete code so i would say this is the really best functionality of service now if you have really big code or any custom code you have which you want to utilize in multiple scripts i would recommend to create it in your syntax editor macro and utilize it so this was all about preparation for scripting in servicenow client-side scripting now this is our main topic for this particular session that is client-side scripting if you remember from one of my video i posted that is the first part of my developer training is about three types of scripting we have in servicenow one is client side scripting another is server side scripting and third one is mid server scripting so the major scripting which we use like as a core platform developer we use client-side scripting and server-side scripting client-side scripting is something we use if you want to change something on user's browser if you want to place something around user's browser whatever he sees in the front end and we want to modulate something maybe show some data that's how we use client-side scripting which basically gets loaded on the client that means user's browser so what are we going to learn so in this particular session we're going to talk about client side scripting and the four topics which we will learn today is what is client side scripting where to use client-side scripting client-side apis and methods use cases of client-side scripting so i will show you some practical examples directly on my personal developer instance that how exactly you code on on client-side scripting in-service now client-side scripting client-side scripts execute within a user's browser and are used to manage forms and form fields so if anything which is running on user's browser you are showing on the screen on the user's browser you have to change something on the browser then it comes client-side scripting as an example we have mentioned some of the examples right like show an alert when form loads so if i'm loading a loading an incident form and i want to populate an alert i can do it with the help of clients site scripting validate form data if i'm loading the form and the user is filling the form and i want to validate that data i can do it directly from the front end i can do it from the user's browser ends with the help of client script then if i want to show and hide some choices of field so if i have a choice field it has 10 choices now i just want to uh make five choices visible for the users in that case i will utilize client-side scripting if i want to hide or show a section on on incident form or change form then i will utilize client-side scripting if i want to set a value on the form then i will also again use client-side scripting confirmation on submit so for example if user has filled in the form and once he clicks on submit i want to give a pop-up like a confirmation to the user i can also do that like are you sure you want to submit this incident those are the summits those are some examples in which we definitely need to do client-side scripting where to use client-side scripting now where exactly you can write these client-side scripting in service now so there are a lot of places in service now like functionalities where you can exactly write the client steps in order to utilize in different functionalities for example ajax client scripts ui policies service catalog ui policy client scripts ui actions ui context menus and then validation scripts now these are some places where you can write client-side scripting i will definitely show you all the examples in one of my video however in this particular session we are just talking about what is a client-side scripting but overall bigger use cases for each uh functionality like client scripts ui policy we have a different section we have a different session for that and in this in this session we are just talking about what is the client-side scripting but i will still show you some of the examples that how exactly we use them client-side glide classes now servicenow provides a lot of apis in order to use client client-side scripting so if you want to change something on the form if you want to fetch some data for the user these are the things that you use as part of the apis for example glide ajax you have a glide user these are the apis which servicenow provides they provide some apis and methods so that you can utilize them to to perform your client side scripting like glide ajax glide user glide menu glide list 2 glide form and glide dialog window we have some more as well and i will let you know that how exactly you can see all those apis in servicenow client-side api as i mentioned in my previous slide these are some other as well like clyde ajax glide flow glide form glide model glide dialog window glide list 2 glide document v3 these are some other client-side apis as well now i will mention a url in my video in your description you will find that url and you can just see the list of apis we have for a client in servicenow the first api we will talk about now this api is being used i think every time i would say so this is the glide user is used to get information about the logged in user now if you want to get some information about the logged in user then you have to use this api so the object which is used to access glide user methods is g underscore user it is used only in client and the syntax we have is like g underscore user dot gly's user method and i will definitely show you how to use these apis so we will just learn about few major apis which i think you will you will use them in your everyday coding but i will show you the practical example of each and every api we have for client in-service now glide ajax glide ajax is used to call server-side code from client that means if you want to fetch some data on the client from the server then you use glide ajax glide ajax instance is called with glide ajax constructor it is used client scripting syntax of glide ajax is where ga equal to nuclide ajax is kept include glide form glide form is used to customize forms and perform some activities on the form the object which is used to access glideform method is g underscore form it is used only in client so only client you don't you're not going to use it in on server end in in server scripting no it is only being used in your client and then the syntax we have is like g underscore form dot glide form method and we have some parameters and we will see further that how exactly you use this light form so every api has its own utilization own feature i would say so in order to get some functionality uh fulfilled you have to use these apis next is glide dialog window now glide dialog window is used for displaying a dialog in current window and frame it is used only in client so on the form for example you want to put some pop-up then you can use this light dialog window maybe you want users to put some extra information on the incident form and you want to give a pop-up where the films fill something and then you push that data into your servicenow form you can do it with the help of glide dialog window now servicenow is also keep on coming up with new versions for these kind of apis like glide dialogue window i think they came up with glide model then uh they also have in list version they have glide list two they also have glide glide list version three so they are coming up with different apis now how exactly you can access all these apis in just one list i will pay as i mentioned i will paste that link in my description of the video practical lab and use cases so we just talked about what what exactly the client side scripting is and where exactly you will use them now i will go to my personal developer instance and i will show you each and every example so that you can understand that what exactly uh client-side scripting is and why exactly we use that or in what situation in what use case you have to use client-side scripting not server-side or maybe mid server scripting so let's take a look this is my personal developer instance now first i will show you about glide form now glideform api provide methods to customize forms so if you want to customize the form you can utilize this glideform api now how i will show you for example you have this incident i will go to open i will click on client script now this is one of the place if you remember we talked about the where exactly you can use client-side scripting so this is one of this place where we can write our client-side scripting that is called client scripts and i think you can you can definitely understand what the name we have client scripts so it is not a server script it's just a client which runs on the browser user's browser so if i click on new so i will show you this api and all the methods we have so i just clicked on new it's running a little bit slow maybe because of my internet connection okay now let's get loaded so i will just create a test script basically which runs on incident table uh ui type desktop for now and i will run it on load so whenever incident form will load we will run this script now this is what servicenow has kind of i would say uh power that you don't have to mention something that where or in your code that where exactly it will run it will automatically run on the client with some conditions but now you will mention some scripts now as we talked about the g underscore form so if you remember one of the api i mentioned in my slide that is g underscore form object now if i type g underscore form i'm mentioning this object and if i put dot it will automatically show me the methods which which i can use for this particular api so glide form has this object and this object has this all these methods we can call them and we can have as per the functionality they have so you can see for example add decoration you can see adds an icon on fields label this method is available starting with the fuji release we can try to use let's see which one we can use maybe we can put add error message for now so if i put add error message here i can put the error message i want to show on load so this is a test script now i'm just using on the form because i'm doing some customization on the form okay on the client users client so i'm putting g underscore form and then i am just putting the method add error message so it will populate the error message on incident form on load because we have already selected the load that on what condition it should uh run this script so i have added that what i will do i will just click on save now if you will glow here or maybe i can just click here and open the form and once form is loaded see you can see this error message this is a test script so it's quite simple you don't have to put a lot of efforts in showing this error so that's the reason as i mentioned with the help of g underscore form it is giving you different methods so that you can utilize it on your client and you can use any function you want or any functionality you are looking for but it has to be available with with that particular um object or you should have that method for and for that scripting basically uh if i go back to same climb script so let me go over there this is the one which we created test one ah this is the script field we have and here we have mentioned our object and method now with the same way you can use any method you want for g unesco form now you also have some other apis which we discussed like glide user which shows you the information about the user and how exactly it will show so for example if i do g underscore user dot when i do dot it says first name so for example i can mention where a equal to g underscore user dot get full name that's it i just put the colon and that's it so i'm i'm i'm done with the semicolon and with this way it will return the user's full name how i can show you right away so for example if i put jesus curve form dot add and this time i'm not going to put error message i'm going to put info message so every different method has different functionality so i'm going to use info message i will put here and i will put yeah maybe you have logged in as i'll put plus a i will save it so currently as you know i have logged in as system administrator that's my name so let's see what it says if i click here and i open any form cool it says this is a test script that was that came from our previous script we had like gnscore form and the next one is general score user we just mentioned get full name i didn't put anything else so now it is showing you have logged in as system administrator automatically i i didn't do anything else i just used the out of the box servicenow api to show this then logged in user's name but this is how you can utilize uh g underscore uh user now i will have a separate section separate session for all these major apis we have like g underscore form g underscore user how do we utilize them in the different use cases so this is for g underscore user so if you want to have any information related to user you want to have first name last name full name and there are some other methods as well just use them and get that information wherever you want to populate push push on the field whatever you want to do on the client you can do that let's talk about a use case for client-side scripting suppose your client or your customer reaches out to you and asks you to show a pop-up on on the incident form when anyone changes uh the impacted urgency to high high or maybe the priority is high so if i go to the form and if i'm creating a new incident and i make impact as high urgency is high and the priority will automatically become critical so when it becomes critical as as a as an end user i should see a pop-up that hey do you really want to submit priority one incident that kind of pop up your requirement uh like requester is looking for now in order to fulfill this requirement we will only do client-side scripting because now we have to show the pop-up and how exactly we will we will achieve this goal so let's create a client script so i will go here i will create a client script i will create another one maybe this time so i'm creating new client script and i will give it a name show alert on p1 it would be on incident table ui type should be desktop type i will mention on change now i'm not going to do it i can also do it on submit so for example if user clicks on submit button he he is going to create the incident then also i can do that but what i want i want to do it in just what go first go so when he changes the priority so and the field name i will mention so whenever you will click this type as on change it will automatically open a new field called feed name so as of now i will put priority here so what i will do first i will get the value of priority so i can do where a equal to g underscore form dot maybe i put get value and i will so you can see if i do get value whenever i do that you can see it also showing you that what exactly you need to use as parameter it says field name as a string so i can mention what field we are talking about priority so we will get we will get the value of priority we can also do it without doing that like we can use maybe old value or new value yes so maybe i can comment it for now and what i will do and i will do it on change so if new value is equal to one and i'm sure that priority is one maybe we can check it later but that value should be i think one so if i have a q value as 1 so new value is the one we are changing it so if new value is equal to equal to 1 i should see a alert you are going to create p1 incident so i will save this if i click here maybe i go to this and yep see so when i'm changing this to p1 it is automatically giving me that you are going to create a p1 incident i will click just okay yes that i want to if you want to make it as a confirmation you can also do that so just you have to in place of alert you can put confirm so you will have two boxes okay or cancel you can also do that so this is how uh you create these alerts with the help of client-side scripting but we will have proper use cases for ap every api we have like glide user uh glide form glide dialog box glide dialog window glide model all these major apis which are basically used every day in in a in the life of a developer like whenever you will do whenever you will uh like fulfill the requirement of your stakeholders you will definitely utilize these apis so we will talk about those apis in our in our later uh videos and i will definitely post them so this was all about our client-side scripting our next session will be around server-side scripting server-side scripting what are we going to learn today we are going to learn about what is server-side scripting where to use server-side scripting server-side api and methods use cases of server-side scripting let's start with what is server-side scripting server side scripts they execute on server and database ideally in order to perform some operations if you get some value from the server then you uh use server-side scripting if you're working on incident form and you have to fetch some data um which is in the database and you want to fetch a value of a record then you can use the server side scripting so following are some examples which shows what is server side scripting like where exactly you will use server side scripting for example you are updating a field when record is inserted so when you are inserting incident record or any change record or problem record and you want to update a field that you can do with the help of server side scripting setting a value on a field when parent record is updated if you want to set a value on a field of a child if for example parent incident or parent record is updated validate the role of logged in user so whomsoever user has logged in what kind of role it has that you can validate with the help of server-side scripting you can generate events so when if you want to generate some email events of service now then you have to use server-side scripting send email if you want to send notifications to any any particular users or group then in that case you have to use server side scripting where to use server-side scripting now as we saw there are so many places for client-side scripting similarly we also have some places where you can write server-side code that is server-side scripting as an example you can write these server side code on access controls that is acl access control list then business rules script includes transform maps workflow now these are some places there are some other places where you can write both client side and server side for that we can we can uh learn later and i will definitely post one of the video regarding where you can write both the codes as an example ui actions in ui action you can write server side code as well you can write uh client side code as well even in script include skipped include can be written for client side as well ideally the code will be the server side but it can be written for client as well and just to call any function directly from script include we will see how exactly you can utilize script include as well classes of server side now these are some server side classes which you utilize in service now as an example you can see on the screen we have glide racket glide element glide data date time glide aggregate light system these are all apis now as i as i mentioned in my previous video that servicenow provides lot of classes for client side and server side so that you can utilize those classes and uh just just use them classes in your code and perform the operations or maybe if you have some functionalities you can fulfill those functionalities with the help of these classes and apis we have from servicenow glide record now this is i would say one of the important api for server side code which you will use i i will say almost every day if you will if you are a servicenow developer then you will definitely use this api for sure every time because this record is used for database operations if you want to manipulate data you have to use glide record so anything you want to do as part of your server you want to fetch some rackets you want to insert some brackets you want to change some brackets update some rackets delete some brackets you can do it with the help of glide racket in this video i will just show you a few examples of what exactly we say server side scripting but i will definitely post another video or or i would say more videos which will talk about all these apis even for client side even for uh server side like light record glide user uh glide form all these apis we have from servicenow major apis important apis which every developer has to use every day almost every day so glide record as i mentioned on the screen that it is used only in server side syntax is great instance of glide record class we create the instance how we create it you create the gr you create the glide record object you create a variable that is gr and you have glide record and then you mention the table name now practically i will show you later that how exactly you utilize glide racket then we have glide system glide system is used to get information about system and current logged in user it just if you want to get some information so servicenow has already created this class so you can with the help of methods of these cl class you can get lot of information it is referred by a variable gs so how you use this glide system there's a syntax gs dot glide system method you mentioned the method and if you have some parameter that's how you use glide system glide aggregate now this is also one of the important class of service now glide aggregate is used to perform aggregation operation on the database that means if you want to do any kind of account or sum that's how you do average you do it with the help of glide aggregate now glide aggregate and glide racket they both do same kind of activity as part of the database operation but in glide racket you fetch the record and you can do lot of changes but glide aggregate is just utilized in order to do some functionality some operations like count some uh minimum maximum average that's what you can do with the help of glide aggregate it's an extension of glide record class that's really important thing to know that it is an extension of glide racket class the syntax we have for glide aggregate it's quite similar with glide racket as you can see on the screen we have where agg that's a variable we are creating so new glide aggregate and then we have incident and that means it's a table so in in grade record you mentioned the table name in braces and same here you you just mentioned the table name so this is the uh class where you can uh do some operations related to count some average practical lab and use cases now these are not only the one which are the classes of server side scripting there are lot of there are multiple server side apis provided by servicenow now how you can find those apis even on servicenow documentation there is a site called developer.servicenow.com you go to that site there's a there's a i think tab which called there's a link called api when you click on that api it will show you three menus one is server client and rest rest is for the web services rest we have service apis which servicenow is providing and the another to our uh server and client client we have already talked about i have already pasted the link of that particular list of apis in my previous video i will also do the same for server side uh apis as well now let's let's take a look for some exam some of the examples and use cases that how exactly you use this server side scripting or when exactly would you think that okay now i have to create or write a code for server side so let's take a look this is my personal developer instance now i will show you how to write server side script so server side script as i mentioned earlier we do like a database operations like client record so if i go to incident or maybe uh let me show you with the help of fix the script not directly on a table uh in your admin you must have read fixed script now fix the script it just uh i would say it's a open platform coding where if you if you have some task for example i will give you a best example that if you want to update uh one lakh records now in order to do that you have to write a fixed script service now also provides background script where you can write the code as per you want but the recommended approach is writing a fixed script so i will just make it a test for demo now here this is the script disk field where we can write this script now what is a server side code as i mentioned now if you remember we talked about different api classes of client side as well which runs on form which then saw form fields now here the the the code is slightly different because now we work on the directly on the server directly on the system and how exactly we can fetch the records as an example let me show you so i will start with where gr equal to new i'm creating the glide record object now you can see it says it is automatically showing that what exactly it needs as part of the parameters it's it needs table name so what i will do i will mention here incident and this table name is exact table name it is not a display name it is exact table name we have so i will put semicolon then i will do gr so as i mentioned there are a lot of methods for this client bracket so we have created the glide record instance now i will access some of the methods so that i can uh create my query to do some operations on the database so as of now i just want to fetch 10 records of incident let's see that so i will put add these are the methods multiple methods are there for client record so we are using the same variable as you have created that instance so what i will do i will go for add active query now what this will do for me this will pull all the active incidents i will semicolon then i will do gr dot query and then i will do while gr dot next here i can type maybe gs dot log and the incident number is and i will put here gr dot number if i will save this fixed script now i will show you i will i'm going to run this fixed script so if i run this fixed script and proceed great now all the active incidents are showing right here now if i want to limit the records i will do one thing i will do gr dot set limit now this is one of the method which is used for glide racket and you can read sets the maximum number of racket in the glide record to be fetched in the next query so what i can do i can do set limit i just press the tab and i will put for example five now it will just give me five incident numbers i will save it again and now i will run it as you can see initially we were getting every incident which were active but now it is showing me all the active incidents but i have set the limit as five so now it is showing me just five incidents so this is a server side script that's how you do we have some other apis as i mentioned glide aggregate glide user as well we do have glide user in client as well but here it's totally different yes we use it glide user with the help of glide system i will show you there will be a separate video for all the important apis i am going to post as part of this developer training i am going to post separate videos for all the important apis we have so that you have better understanding now in my next section i am going to talk about all these codings that how exactly we do these codings for different areas like server side or client side why we why we created that variable this is basically part of the javascript so as i mentioned earlier that you should be aware of javascript as well you should be completed code academy code the code academy course that's really important so i would definitely recommend if you're not able to understand why i'm putting vial or all these loops why i'm doing that that the only reason that you're not able to understand because you have not completed or you're not aware of javascript yet so i would definitely recommend that you should definitely read javascript you should complete that code academy course and then watch developer training so as of now i'm going to end this video this session uh this was just all about server side scripting that what is a server-side scripting but as i mentioned i'm going to tell you each and every api which is mostly used i will show you all the use cases i'm also going to tell you what most of the organizations come with different requirements so that as a developer how exactly you can fulfill those requirements for your customers for your clients so today's topic would be client scripts now in my previous videos you must have learned about that where exactly we can do scripting in servicenow and there are two types of scripting one is client-side scripting and server-side scripting and you also learned where exactly you can use those client-side and server-side scripting now first place where we can do the scripting and service now is client scripts so client script is a place where you can do the scripting it's a functionality provided by servicenow where you can write the client scripts in order to do work on the form so this is a client-side scripting this is not a server side it runs on client side so this is overall client-side scripting so let's take a look what are we going to learn what is client script when to use client script client script form overview use cases of client script this is what we are going to learn from end to end about client scripts client script client script is used to manage forms and form fields in real time it is executed on the browser we already talked about client-side scripting it's quite similar because it's it will run on client side and if we talk about the client side scripting the major thing or major functionality which you will think in your mind would be client script and if you get your any requirement which has to be there with the client side then you will always think of clients script there are other places as well where you can do client-side scripting but majorly you will think about client script so you can see the client script form we will we will see it later that how exactly you create client scripts and how exactly it runs on your servicenow system when to use client script now these are some examples which shows when exactly you should think of writing a client script for example show the alert when form loads so as an example your servicenow end user opens the incident form so when he opens the incident form if you want to show some alert then you can use client script show a message when a field value changes and servicenow or maybe on incident form if you are changing a field value when you want to show some message then you can should write client script change a field value when another field changes on the form that is one of the example hide and show choices of a field if you want to show or hide some choices on the form then you should write client script and hide or show a section so you have tabs on incident form or change form any form if you have tabs or you also called sections you can if you want to hide or show on some conditions then you should write client script client script form now first how do you locate client scripts now in system definition you will find a module called client scripts if you will click on that module you will see list of client scripts which are being used in your service now system if you have just uh get the personal developer instance as of now you have not customized anything then you will find all the baseline client script that means in order to build servicenow system or all the modules they have they have created some baseline scripts so that you will find when you will when you will go to system definition and client scripts and this is the form on the screen you can see it says client script it's a new record it has some fields and it it gives you an opportunity to write the script as well which will run on your form so let's talk about client scripts form fields what are the different fields what are their utilization basically why we have those fields on the client script form so client script form fields the first field we have is name which will mention the name of the client script so when you will create an uh client script you will just mention the name any name you want your name should always be unique so if you are writing a client script for different tables so it should be unique one more i would say recommendation which i would i want to give is always try to use your organization's name as a prefix because you will have multiple client scripts so in order to differentiate the client scripts name that what what scripts are baseline and what is customized then with the help of the prefix you can know okay this is customized and this is the baseline script so if you're part of any organization try to just use that prefix in the beginning next field we have table table is the table of the form on which client scripts needs to be run so for example you want to uh show something or run this client script or incident form then you have to select incident table if you want to run this client script on change table then you have to select change table so any form you want to manipulate or you want to run this client script you have to select that table next is ui type on what type of ui it should run so you have to select there are some options like desktop mobile or portal or both that's what you uh that's kind of options you get in this ui type so for example your users might use this form or might open this form on your mobile as well or on your desktop as well so you can put that option whether you want to run this client script just on your mobile or portal or you want to just run this on your desktop when user is opening the service now in just desktop that kind of option servicenow is giving you because it might happen that there are some functionalities or they want there are some scripts which you want to run on the form just in mobile maybe or maybe sometimes just in desktop so it's up to you as per the configuration if you want to run that functionality every time then you have to select both then we have type type of the client script now servicenow provides four types of functionality in client script now client script has four types that is on load on change on submit and on cell edit these are four types of uh client script and we will talk about it later then we have application this is the scope of client script i think i have never posted any video related to scope servicenow has i think they came up with i don't remember the exact version maybe with fuji they came up with scope scope scoped application so as of now it is global initially i think in the beginning everything was global but now servicenow has come up with this scoped application as well so now you have that option called application and it says global it's global scope as of now if your application is running or your whatever table you have created if it's in a different scope then you can select that scope as well if you want to run this client script in that scope you can do that but as of now as an example we will just show global scope next field we have active inactive so for example you created a client script you got some error and you for for some time you want to deactivate that client script so that is what it's just a flag for making this client script working or not working if you want to make it working you have to keep this active checkbox checked if you if you don't want to make it working you have to keep this checkbox unchecked inherited if the client script should be extended so for example if you have uh any uh maybe you're running this this client script on incident table and there are some tables which are inherited uh from incident table or as an example if you write this client scroll on task table so now most of the tables we have in service now like where we work as a task they are inherited from tasks table in that case if you really want to cascade and extend that from client script to other tables as well you can just mention this check box so if client script should be extended or not you have you can check it then we have global this is just for view of the form so as you know in servicenow we have different views now if you want to run this client script on a particular view then you can mention that view but if you want to make it as global that whatever view user opens it should run everywhere then you have to select global then you have description field here you just mentioned the description of the functionality of the transcript that what is the use of this client script that's what you can mention um as i mentioned when you put the name of the client script you should mention somehow relevant to your functionality as an example set mandatory field or populate an alert when priority is p1 something like that its name shouldn't be that much long but if you want to explain that you can explain in description then you have messages it is used to show message when client script runs so basically when your client script runs and you want to show some message and you will uh put a method called get message and then you can put the message here it will automatically show that message so you don't have to put that message in that particular parameter you can use it directly from here and the last field we have which is the most important field of client script that is script field now we already already talked about the coding we are already talking about scripting so here you will write your script which will run when different action or basically it depends on the trigger so if you will see the section the above section it it's totally talks about trigger that these are the condition not name but all these things like table ui type uh then type active or inactive these are kind of triggers but when you say skipped it is just action which will run so if that if uh when form is uh loading if your form is getting uh running the client script and it matches the condition of this particular client script then your script will run this is how this process works so the above section is trigger and the lower section is what have to be run that's what you can mention over here and that will run your script types of client script as i mentioned earlier there are four types of client scripts one is onload on change submit on sell edit now what are their functionalities when exactly you have to select onload on change on submit and on sell edit so let's take a look onload now a script will run when form loads and before control is given to the user now if you want to run the script when your form is loading and you will give the control to the user before that step if that is the case then you will use onload type it is used when something needs to be changed on the form while it is loading so for example if you're loading the form and if you want some action to be taken then you will use the type as on load onload function will be automatically populated in the script field when all load type is selected on the form i will show you later in my personal developer instance that how exactly it does that on change script will run when value of any field is updated or changed so when you want to run your script if for example if any field is getting changed from an end user if it is used to perform some operation as per the field changed on change function will be automatically populated in the script field when on change type is selected on the form it has parameters so if you remember in on load we don't have any parameter the onload function is just directly declared that's it it doesn't have any parameter but on change function has some parameters like you can see on the screen that is control old value new value is loading its template so these are some uh parameters now what kind of like values these parameters hold so control is the name of the field whose value is changed so if you will use this control uh then it will automatically pull the name of the field which which is changing that's what it gets the value then we have old value old value is a field which you are changing what would its old value this old value parameter will hold that value then we have new value new value if user is changing to the new value this parameter will hold that value is loading is loading will check whether your form is loading or not that's what it's just kind of a confirmation it is telling you true or false and then we have is template it will check whether this change whatever change i'm doing is it is dependent on the template that you can see with the help of is template so it's just a boolean value indicating whether the change occurred with the population of the field by a template that's what it it checks so these are all parameters of on change and we will see practically in my personal developer instance on submit on submit is something when you submit the form so script will run when form is submitted or saved it is used to perform validations before form is saved that's what you do so for example if you are done with the change on the form and you want to click on submit and uh but you want some validations before submit then you can use on submit now on submit function will be automatically populated in the script field when on submit type is selected on the form next is on cell edit this uh client script type is quite different from other three now all other three client scripts uh type they were for forms basically when you work on the form now this client script type is for list view so script will run when a field value changes on list so if your user is on the list and from the list view if he changes maybe priority or maybe some other field and you you want to run some script you want to do some uh you want to perform some actions in that case you will use on cell edit on cell edit function will be automatically populated in the script field where on cell edit type is selected on the form now onsell edit also has some parameters like cis ids so society of the edited item so whatever item you are editing it will automatically hold that value that says id society of that particular record table the table name of the edited item old values is the old value of the edited cell new value is the value which you know which your user is changing now and then we have call back a callback will continue the execution of other related cell edit scripts that's what we have called back we will see the practical examples of all these types of client scripts practical lab and use cases now before we talk about use cases let me show you whatever we talked about these form fields types of client scripts let me show you give you a walkthrough that how exactly these options are visible on the client script form and how exactly you can use them so let's take a look this is my personal developer instance so let me go to system definition i will show you where we have this clan script so we have this here you can also see it by typing here client script it is under system definition if i click client scripts these are the baseline scripts uh these one were created by me but apart from that all these client scripts are baseline client scripts these are not customized client scripts these are directly from servicenow now if i click on create new you will see the same form which we were talking about that client script form all these fields which we talked about now the important thing which i told you the table if you click this button you can select any table if you select ui type you can see desktop mobile service portal or all that is both and then you have ui type as on cell edit change on load on submit if you remember we talked about the auto population of the function so you will see here if i select on submit you will see there's a script field will automatically show the on submit function you don't have to uh type that if i select onload it will show me on load if i select on change this will show me on change function automatically with parameters which we talked about now what is this we will learn it later then we have on cell edit if i select on cell edit you can see it changed the function and it became on cell edit function with those parameters so this is how you see a client script and you can create a new client script with the help of these types of client script as per your requirement now let's see our use cases so i have mentioned two or three use cases due to which you will you'll be able to understand that how this client script works that why exactly we create client script and in what case basically and what condition that you have to write these client scripts so let's take a look this is our first use case now in this use case the requirement is that set the value of caller field with current logged in user when form loads so as an example if your client give you a requirement in which when an end user opens a servicenow incident form in order to submit the new incident then it should populate the current logged in user that user's name automatically in caller field so that is the requirement how exactly we can fulfill this requirements we will take a look light camera action so the first use case is set the value of caller field with current logged in user when form loads so it is one of the requirement in which your client says that light camera action this is the first use case of client script so the requirement is that we have to set the value of claw of field with current logged in user when form loads so for example if an if you have an end user and he clicks or create new button and uh form loads then his name should be automatically populated on caller field as of now this functionality is not given out of the box so let's take a look this is our personal developer instance i'll click on create new if i click on create new you can see caller field is not automatically populated so the requirement is we have to populate it automatically if i'm clicking on a clear create new button and form gets loaded off incident so what i will do i will go to client script i will create a client script so in order to fulfill this requirement because this functionality is related to client-side requirement then when form loads i have to push some value in that case i will to set caller so this is the name of the client script table is incident because we want to show it on instant form ui type we can keep as of now desktop type now when exactly you want it now as per the requirement it has to be on load so i'm selecting onload now you can see the function on load automatically populates here so this function is already there we don't want to put description for now but if you want you can do that so what i'm going to do here i will first create a variable which will capture the value of current logged in user society and how exactly we can do that you can do it so just create any variable you want so i'm creating a user variable and then i will put g underscore user dot now this is the api method which you have to use that is g underscore user dot user id when i press tab it will come over here i will put semicolon and here i will put g underscore form now we have to set some value in a caller field for setting a value service now provides an api with g underscore form there's a method called set value and you can read sets the value and the display value of field will display value if there is no display value so it sets the value on a field so i select set display value the first parameter which i have to select is field name so what i can do the feed name is caller id now this is this field name is not label name this is the column name basically yes the real name the backend name i would say you have selected caller id and then i will push user because that's a reference value so we can pull we can push uh society of the user the current logged in user now that genderscore.userid will give you the society of the user so if i will make a comment here get the sys id of the logged in user just to help you now here i am setting the value i'm putting the semicolon setting the field value i'm just adding the comment i think it's the best practice of scripting and i'm clicking on save so you must have seen earlier that when i was clicking on new button uh it was not pushing that value in caller field but now whenever i click on this create new button you will see yes it is automatically populating the system administrator because i am logged in as a system administrator that's reason it is pushing sister administrator's name so if any of the user will open this form his name will be pushed automatically here now there's still a tweak here that this functionality we have written it will run in every case that means let me show you an example these are all existing incidents you can see currently david miller is the caller for this incident so it means that they will call david miller must have uh called for creation creation of the incident now if i am clicking and opening this incident what it will do you can see it change the name that means that is a kind of a bug because you are changing uh the client script you have changed create a new client script and it is automatically pushing as per the script you have written now what should be the best thing so that it doesn't do this particular operation for all the existing incidents because as per the requirement this should only happen when you create a new ticket so in order to do that we will go back to our client script now the only option for for this one is that this ticket is a new ticket it's it's not a it's not a old ticket it's not an existing ticket in order to do that what you can do is new record so if when your form is getting loaded if it's a new record then only it should run so if your form is new then it should run in that case so g underscore form api also gives you method called is new record okay so if this and i will click on save here and i will go to my incident so here we have david miller because now we have to uh like remember one point we are just pushing the data from that client from the browser end it has not been saved yet yes so it's not something that if you are pushing something from client it will be saved automatically no you have to save it so i'm opening this incident now this time it will not push the data yep so form has already been loaded and you can see it is not pushing system administrator that means the current logged in user's name now in caller field and the reason behind it because we reached we used that new condition that if this particular form load is a new record if this form is new record then only it would uh push that data else not so this is the first use case of client script let's talk about the second use case show an alert when priority of the incident changes to p1 in this use case the requirement is that if a user changes the priority of the incident to p1 and it should show an alert to the user that you are going to submit the p1 incident something like that that kind of alert message can be different as per the requirement but this is what we want in this particular situation now how client script can fulfill this requirement let's see that so i'm opening my personal developer instance now in this case i will show you first whether it is showing that message or not if i click on existing incident and this this functionality has to work for both the situations even for new incidents even for existing incidents so currently the priority is p4 and if i'm changing it to p1 it is not giving me any error and as you know that priority is read only field it can only be changed by user with impact and urgency combination so if you are selecting impact and urgency is high priority would be critical in order to show that alert i'm going to create client script this is the set caller example which we use so i'm going to create a new client script and i can just mention alert on p1 it will run on desktop type in this case now this is something uh change of the field so if user is changing a field then only you have to run this script you have to show that alert in that case you will not use onload you will select on change because user is changing something so what happens when user uh like perform some changes on the form fields then what action you want this is the one of the situation now when you select on change uh type it will automatically populate a new field called field name so you have to select the field name then what what field this change should run so i have selected priority now as we talked earlier that you can see that function of that particular type will automatically populate but in an on on change case you must have seen some parameters which we talked about earlier like control old value new value and this is also the condition which we have now this condition automatically gets populated with the function and the reason it just says that if is loading so form is getting loaded and new value is empty so we don't have any new value when somebody is changing in that case this will not return anything so nothing will happen but while you are changing something as in the same go you also want to put some action on the loading then you can utilize this else not and apart from that you will write your code right from here not in that particular section you can leave but if you really want to you want some action in loading then you can do that so in this case we want to show an alert if priority changes to priority one so how exactly we will do that we will just write if new value now new value holds the new value which has been changed too so maybe initially it was priority two now it has become p1 when whenever new value will have that one as a value then only it should work so new value we will select the backend value that is one so if new value is 1 then we'll put alert and alert would be you are going to submit p1 incident the current priority of incident is now here you can put the value and that would be old value so old value this parameter already holds that value so you don't have to clear or declare a variable or something you just need to put that old value and it should work so semicolon so we have the script and i'm going to save this so if i go to create new so currently the priority is p5 basically but if i change it to high yep you are going to submit p1 incident and the current the current priority of the incident is five now why it is showing five because it is holding the value the value of uh that particular field so if you want you can also display the uh like display value that label name but you have to do some other like coding you have to get that value if that is five then you can populate it as well so this is the use case in which you can show an alert with the help of a client script let's check another use case we have set an alert on submission of incident so in this use case if i'm submitting an incident i should get an alert so let's take a look this is my personal developer instance i am creating a client script alert on submit i will make it as on submit and i will just put alert and i will type here thanks for creating and incident this will be assigned to service desk just a message we want to populate to the user so i am just saving this now i'll go to here and i put a test and i click on save when i am clicking on save you can see it says thanks for creating an incident this will be assigned to service desk and i click on ok and then that that particular form is saved now let's see what happens for existing so i'm here right now and i'm clicking on save if i'm clicking on save now this is the difference you can see that i'm still getting that alert because you have not put in some condition whether the submit is just for new record or existing record so as as of now it is taking for every situation so submit is whenever you are saving the form then it will take it as a submit so don't be confused so submit is just like a save but it's it's whenever you are saving the record you're submitting the form in that case you want to put something you want to put some validations in that case you can utilize submit as i mentioned in my in my session that summit is basically used for validations so before entering before submitting the ticket do you want to check some validations do you want to do some validations on the form so that you alert the user that hey you did not fill this it is similar to mandatory ideally but it might happen that sometimes you want to check some short descriptions maybe or some other fields you can you want to put some kind of validations in that situation this is being used this is about on submit so these are the three use cases of client script i'm going to post second part of this client script in which i'm going to talk about g underscore form and g underscore user methods and apis we have from servicenow in this session we are going to talk about common api and methods used in client scripts in a previous session we talked about client scripts where do we write client scripts how do we write client scripts and we also learned some examples some use cases now i am going to talk about api which are being used in client client scripts in detail that's what we are going to learn and i am going to talk about two major api which we have from servicenow those are and that's our next topic that is what are we going to learn and that is glide form and its methods glide user and its methods so whenever when your customer or your uh client will ask you some of the requirement and in that requirement you think of okay this requirement i can fulfill with the help of client script not any other functionality which we have in servicenow but with the client script now when you will start writing that client script you have to have you have to be aware of some api and method so that you can write and fulfill the functionality and that's our goal of this particular session so let's talk about first glide form and its methods we will also post the second follow-up session just after this video and that will be on glide user and its methods so whatever methods we have for both the apis we are going to talk about those methods today so let's start with glide form that's that's our uh like one of the important api i would say and the object which we use for glide form that is g underscore form so the glide form api it provides a method to customize forms and that's what we learned in one of our previous session so glideform.js it is the javascript class that containing these methods and the globe global object we have is g underscore form that is used to access those methods so let's start with our first method that is add decoration so when you will type on client script that is g underscore form dot add decoration then you can see this method and you can utilize it and the use case we have here is on incident form show user icon when contact field is filled in so let's go to my personal developer instance and let's see the example and that is what i'm going to do today i'm i'm not going to show you example of all the methods we will tell you the what are the methods we have but the most important api or methods we have i'm going to talk about example of those methods so let's start with add decoration this is my personal developer instance and have this incident form what i will do i will right click here and i will go to my client scripts so i will create a new client script and we are going to do this on change basically and that's a requirement that if um if client if if caller is empty if if not empty then it should show that icon so in that case you can also uh show it on uh show it on on load as well so what i do so whenever i fill some data in in color then i should see it so in this case um glide form demo on change so table is already selected i have ui type as desktop here i can select on change because i am going to utilize on change value if i am changing the caller so if new value is not equal to null that's what we should have and then i will type genesco form dot add decoration now this is the method so whenever in in syntax editor whenever you will type the object that g underscore form and you will put a press dot you will automatically get access of all the methods you have for the g underscore form so you can see we have add decoration it also says adds an icon on a fields label i press tab it will give me what kind of parameters are needed so you can see we have field name icon that's a string and then title of that icon so in this case what we can do let's let's pick the icon and how exactly we can do that i will go to my application navigator search for action icons now the this is the list of icons in this case i will also do one thing and it will i think it will give you a better visibility i'm going to zoom this so that i think it will help you to see my scripting better let's keep it 125. i'm sure that now you can see it better so you have this add decoration i'm going to this list what if if i maybe i will copy this word this particular name of the icon first i will put the field name that is scholar underscore id comma and then i will put the name of the icon i'm not putting the last parameter i'm just putting the two parameters here now i am saving this form so client script is saved and you can see we have not selected the field just active that's a mistake i would say so you have to select the caller field and that's what we want so i'm going to save this again and i'm going to incident form so if i go to incident form now this will run only on on change so maybe we can do it for new incident so if i open the new incident and i put the caller so as of now you can see we don't have any any icon here but if i select abraham lincoln so whenever i will select abraham lincoln it added that icon so this is what it does add decoration add error message now add error message shows the error message or kind of alert on on the top of the form so the use case we have is on incident form show alert message to user when priority is set to p1 so in that case i will go to my instance and i want it on change so what i will do i will make it as a comment so this is common now i want this one and i have to make it this one now it will not give me any error i will make it down so if the priority is getting changed to p1 i should see that error so what i will do first i will get the value of the priority so i will do where inc priority equal to i'm just creating a variable unesco form get value i have to get the value of uh the priority now you can also do it but idly in this situation you don't need it basically so let me make it a comment and why you don't need it because you can do it with the help of new value because you already have that you're already saving that value for that field so in this case i will select it as priority and then i will put if same new value is equal to equal to one then genesco form dot add error message so if you remember i mentioned i just press the dot and i have all the methods for genesco form so i have add error message i will press tab it will ask me one parameter and that's a message i want to display so i will mention hi or you are going to create p1 incident that's what message i will mention and i'm going to click on save and this will run on on change basically so i go here and i'm reloading the form i'm changing the impact and urgency to high so you can see in the priority is one and i got that message so you are going to create p1 so this is how you can utilize the g underscore form add error message the next one is add info message it is quite similar to add error message but if you just want to display a message with just blue color it says informational message it is not something like alert message in that case you can use info message so i can show you with the same example so we have this one what i will do i will just change this to info message if i change to info message and i save this so the functionality is similar there's no change in the functionality but the only difference would be that was like an error message and this would look like an info message informational message so if i make it as a p1 so you can think of a situation when your client comes to you then when exactly you have to mention the informational message or alert or like an error message i make it as a p1 you can see now it's in blue color this means it's an informational message it's not an alert or kind of error message but if for example if your your user is doing some mistakes or you want to stop the user alert him in that case you can utilize that add error message add option now add option is also really important method which is used to add the option the choice into your choice field so as a use case you can see i have written on incident form add a choice to contact type field so if i go to my instance we have this contact type field and as of now i have four choices but what if i want to add a new choice called portal so in that case i will go here now i want this to run on load not exactly on change in order to do that i have to write a new client script so i will go to my list of incidents go to client scripts this is client glide form demo on change and i will create a new client script i'll write the name so it will be glide form demo on load i have here on load i will select the onload once i will select the on load it will automatically populate the function here onload function now the script i need to write so we have to add an option so what i will do i will do g underscore form dot add option so the parameters which is needed you can see it says field name choice value and choice label so you know that for choices we always have a value and label so in that case what i will do i will put the field name that is contact underscore type i will put the value i i need to put that is portal and then i will put the label so if i save this and i go back to my incident i reload this when i will reload this then i will see the difference so now initially you were able to see only four choices and if i go here now i will see five choices so portal is automatically added so this is how you can utilize ad option clear options clear options is something to remove all the choices so one of the use case which i have mentioned is if you want to remove all the choices from any i have written as a use case from the state field so in this case if you don't want users to see any of the choice you can make it as clear options user will not be able to select any choice any option from that particular choice field clear value this is really important method on incident form remove text from short description so what if you want to clear uh the value of that field on client so on on one of the condition if you want to remove the short description or any of the field the value of that field you want to make it as empty on client so in that case what you will do i will go to onload and it can be any any client skipped on load on change on submit it's up to you as per your requirement because i am just giving you the demo how exactly you can utilize these methods but the conditions situation it's up to you it's up to your requirement from the client so i'm making it as a comment i'm going down what i do and i do genesco form dot clear value when i put this and i have to put this name of the short description so this is the field name this is the only parameter it needed i'm going to save this this time we are not going to open new incident because we are not going to put anything in in new incident as of now so i am i will open the existing incident i am going here so we have this short description unable to access shared folder if i open this first it will load on the client that means on your browser once it will be loaded you will see you will not see this short description anymore you can see it's it's it's gone now the important part to know here is it's gone from the client it's gone from the browser but not from the database the record is still saved record still has that short description it will not be updated until you are clicking on save so till you if you are just removing it from the client that means it is not getting saved when you will click on save or update then only it will be updated in your table record disable attachments now what if you you got the condition that uh maybe when incident is getting resolved you don't want users to attach any attachment and and that is what i have written as a use case the disabled attachment when incident is resolved so if i go to my incident you can see at the top we have this paper clip icon which with the help of which user can attach any document he wants now i want to put a condition that when user does not see this icon on shouldn't be able to attach anything in that case i will utilize the state field so what i will do if state field is resolved then i should not see this icon to add anything so i will go to onload i will make it as a comment i will go at the bottom i will put where state this is the variable i'm creating genesco form dot get value and i will put the name of the field as state i will put here if state equal to equal to 6 if it is resolved then i will general score form disable attachments colon semicolon then i will i'm going to save this client script and i'm going to back to my incident i'm reloading it now why i'm reloading it every time because you have updated your client script now you have to remember that you you run the client script on client so the when you loaded the previous cli uh like previous form it is still had the previous session so in order to reload it it will refresh and then it will utilize that new client script which you have updated so now you have this paper clip icon if i change this to resolved now you can see it is not changing why it is not changing because we have mentioned as on load so in this case i will show you so now you got really good situation that you can also make it when you're making it as a result this will not be visible but what if if i just open resolved incidents and i am opening this when it is getting loaded and that's what we have written on load once our form got loaded completely and you can see the status resolved and now you cannot attach any i document because you don't have that icon anymore so that's the difference so this is the functionality of disable attachments then we have enable attachment so if you want to enable in another condition then you can also do that it will it will show that icon again flash now flash is also really good method if you want to if you want to get attention of your user in one of the field so it's it's kind of a flash when it kind of uh i would say flash that particular field so that you can get the attention so how exactly it can it can do that let's let's go for uh on load uh i will go to my script i am making this as a comment and i am putting generous score form dot flash so flash is the specified color the specified number of times in the field i press tab it shows me uh the parameter i needed so it shows the widget name the field name and the color and the count so what i will do i will put priority then then i will put the color and that can be blue and how much like count so i will put five if you will put two it will i think it remove in just two seconds i would say even even less than that and if i save this and now i go to my incident reload this you will see the difference so you can see now we have this blue color so if you want to get some attention it might happen that you want to flash it if priority is p1 maybe you want to flash it if uh caller is a vip user in that case you can do that next is get action name now if you want whatever uh whatever button you have clicked if you want to get the value of that action in that case you can use this kit action name get boolean value get boolean value is an is a method which you can utilize to uh check the value of a check box whether that check box is checked or not so you can understand as per the naming convention it says get boolean value whether it should return true or false so if it's a returning true that means it is checked if it's returning false that means it is not checked in that case you want to check the value of a check box then you can utilize get boolean value and in this case i have user's use case that if knowledge checkbox is checked show an info message at the top of the form that's kind of a use case i'm giving a nice example so the syntax would be the same dot get gnscoform.get value now you can whatever value it is returning you can save that in one of the variable and then use it get control now get control is a method to get the elements basically you you get the control of that field and it will return the element html element of that field so for example if you want to uh change the color of incident uh incident uh text maybe or maybe any any field like a short description in that case you can utilize this get control let me show you one of the example so you can see we have this short description test so i will make this as a comment i go at the bottom underscore form get control so the control i want for short description and i will save this value in a variable as i mentioned maybe where a equal to and what i will do a dot style dot color equal to red i am going to save this it is saved i'm going to reload the form once this form will be reloaded now you can see this short description color becomes red now the reason behind it because i'm getting the html element of that particular field and now i want to display it so if you remember if you will if you have learned html ever then you will you'll be able to replicate it that we use style.color it's kind of a css and that's what we are doing right here so it is doing the same thing but with a different functionality of servicenow then we have get decimal value now get decimal value gives you the decimal value of a field so for example if you have any uh percentage field and you want to get the decimal value in that case you can utilize get decimal value so it's the same the syntax is similar generous score form dot get decimal value and you have to mention the field name get into value get into value it's similar to decimal value but it returns the integer value of the field so in this case the parameter which you needed that is the field name and you can mention g underscore form dot get into value and you can mention the field name in that case you will get as a return of the data you will get the integer value of that particular field then we have get label off now this is also really important method that on incident form show alert printing the label now the use case you can think of as per the situation or the requirement you will have but let me show you how exactly you can use this so get label off if i am here i'm going to make it this comment and i will do general school form get label off i as a parameter i need to put the field name and maybe i will do short description now this is the field value the name of the field at the back end not the label so if i save this i can get it but i need to display something in order to do that i have to make it an alert and save this once i will save this i will go to the incident i will reload this when i will reload this it will show me an alert with the name the label name of the short description field and now you can see it says short description so this is how you can utilize get label off then we have get reference now this is the really really important method for any developer because you will utilize this method i would say most of the times yeah i think it definitely depends on the requirement but you will still i think you definitely need to learn about this method so let's take a look how exactly we can utilize this method so as an example as a use case i have mentioned that on incident form show alert if the caller is vip now let me explain a little bit in detail that what is the main use of this uh this method now as i talked about the vip now how do you know in service now the user is a vip user so we know it with the help of a field called vip that's the name of the field vip field if that is checked it's a check box field if that is checked that means that user is a vip user now if we are on our incident form if i talk about the user detail i have it's only in one of the field called caller field and that just has the name in front of me on client so how can i know that this caller is a vip or not if you get this kind of requirement not only for just one reference field like a user any any reference field you have in that situation you can use this really powerful method called get reference in that case what exactly you can do so let me go here so what we need to do if the user is a vip then i should show an alert now that's a requirement show alert if the caller is vip and that should happen on load so what i will do i will do g underscore so first i will save that data so i will put caller is called to jn score form dot get reference now the important part of get reference is parameters and very important part so get when you press tab for get reference it will ask you to put feed name and then callback function what if if you don't put the callback function it will still work but that will be called as a synchronous call to the server but you don't want synchronous call because that that is not recommendable that is also that will also impact the performance of the system so in that case we have to utilize asynchronous call and that will be done with the help of callback function so what we are going to do i'm going to utilize that caller id field name here i will mention the name of the field i will mentioned alert caller so this is the function now i will declare that function function alert caller and i will give a parameter that is caller here and here i will do if caller dot vip equal to true in that case alert hey the the reporter of this is vip user now this is the alert i want to give to the user i press save now let me search for vip user incident and i would really want to show you the difference now if you will see this list i have a lot of callers now this is the vip caller but first i will show you the non vip caller so if i open this incident the form is getting loaded i don't see any alert because the user is not vip now if i go to vip user incident i'm opening this when form is getting loaded you can see the message hey the report of this incident is a vip user that means it is able to check that value directly with the help of get reference so you have to remember you can definitely utilize this this particular method ideally you have some other methods and and features as well from servicenow like g underscore scratchpad that also gives you the another functionality but we will talk about it later but anyhow you want to get the value of any reference field in that case you can utilize this method it's a really powerful but make sure you're not using it without callback function you have to utilize the callback function in order to decry increase the performance of the system then we have get section names now in service now if i if i go here these are the name of the sections now if you will put g underscore form dot get section names it will display all the section names you have with comma all the section names that's what it does so if you want to see the result do alert now every time if you want to and i think if you have learned javascript you will definitely know that if you want to see some output that what kind of output you are getting from any method of service now always go for a log maybe or i think in this case you can always utilize alert i think that's the best way i would say in order to see what kind of output you are getting when you are putting that method if you're not able to get get any output like undefined or something else at least you'll be able to know whether you're writing the right method or not or maybe you're giving some right parameters or not then we have get sections now get sections it's it's quite similar to get section names but get section names give you directly the names of the sections with comma but this one it returns an array of form sections so whatever form sections we have it gives you uh those sections in array that is the main functionality of this method get table name now get table name method returns the name of the table on which your record is on on the record which you're working on so for example you have opened you want to run the client script and you want to know the table name while while running it then you can utilize it idly this would this would be used it might happen that you have to use that table name in that case you can use that and the syntax is still the same that is g underscore form dot get table name then we have get unique value now you get unique value now you can understand that it is returning the unique value and that unique value is the cis id of the record so if you want to on client end if you want to get the society of that particular record maybe you are working on incident change whatever record and you want to get the sys id of the record in that case you can use gender score form get unique value and then it will return the cis id of that particular record if you want to test it as i mentioned earlier do alert alert put the brackets um and then you can put the g underscore form dot get unique value you'll be able to get that on any incident you want or any change you want or any of the record of the system then we have get value get value is also really powerful method so one of the use case we have show alert message when priority is p1 so what is the use case of this get value so i will go to my instance so what i want if the priority of the incident so if i'm loading it i want to show uh an alert message maybe whenever the priority is p1 so i'm doing this i'm i'm just making making it as comment so it's comment i will go little above now when i am loading the form so if priority is p1 i should so i should see that alert message so what i will do where a equal to i will put that in any variable genesco form dot get value if you remember in on change we already have that data like a new value or old value we already saving that data but here we have to get it so what how exactly we can do that you press tab get value you put this name of the field that is priority i go here and i mention if a equal to equal to 1 and then i will put genesco form dot add error message this is a p1 just an example i press save i go to my incident so it is not a p1 so let's open a p1 incident this one if i'm loading it see now you can see it says this is a p1 because the priority is p1 so it is able to get the value of this particular field and then with the taking the value you can utilize in your conditions then we have hide related list now you have related list on your incident form so if i go to this incident if i go at the bottom you can see we have these two related lists now if what if you want to hide it you might get this requirement from your customers or from a client that you don't don't want to show this related list maybe one of the related list or every ever related list in some conditions maybe it might happen in that case so there are two kind of relate highlighted list uh methods you have one is hide related lists that is s you have that means it will hide all the related list of that particular form now if you want to hide just one spec specific related list then you can mention it i have given the use case that show affected ci related list when ci is not empty so in that case i'm not going to show you the complete example but just to show you that how exactly is work you have to type the generous form hide related list so this will this will hide all the related lists and this will hide the specified related list on the form if i press tab it will ask me the parameter the list table name that's what you have to mention here it will automatically hide that so i'm going to make this as comment and go to next api method is live updating now servicenow came up with a feature as you know that if uh i think you can see uh the live live changes that's what they came up with so what if for example if two users are working on the same incident and another user is changing um at the same time maybe some some another field or the same field which another user might update so in that case if that happens is live updating if the if user is interacting on the same form or two users and if something is getting updated now that situation you can get with the help of this method so if that condition is there that means if g underscore is live updating if that is returning true that means you can you can put some conditions so that's the reason we have this particular method that is live updating and it's it's really important uh method i would say then we have is mandatory now as we know we have a servicenow ui policy for making the fields as mandatory read-only um and and visible now you can also do these functionalities and it might happen there can be some situations with that you can't do it just with uh ui policy and you have to use a client script that you have to do some scripting and then only you can you have some conditions to make them as mandatory in that case that is what you have to mention that is is mandatory so if you want to make a field mandatory in some conditions with the help of scripting then you have to mention genesco form dot is mandatory and then you have to put that value so if if you want to check this then you can you use is mandatory you're not setting it you're checking it whether that field is mandatory or not so if that field is mandatory then it will return true is new record now you can understand i think maybe maybe i just i just uh uh because there's this different uh different uh method of uh we have that is set mandatory this one is is mandatory you have to check is it is it mandatory that field that's what you have to put yeah the parameter which you will mention here it's a field name uh and that's what you will do so it will check so if uh in your client skip you want to check if any field is mandatory or not then you can use it with the help of is mandatory is new record now is new record is also another method in which you can validate whether the current record it's a new record or not new record i mean when you click on create new and you're not saving the form so until unless you're not saving the form it is a new record so if you want to check it whether it's a new racket then you have to put this condition this uh put this method and you have to mention gnscoform dot is new record it will return true if record has not been saved yet that is what you can utilize is new record then we have is section visible now this is another method in which you can check whether that section is visible or not now as a parameter it needs one parameter that is uh the name of that section so if it is visible that will it will tell you whether it's true or false remove decoration so if you remember i think our first method we talked about add decoration so if you want to remove any decoration as per any different condition then you can use remove decoration remove option we talked about add option from from our choice field now in this case if you want to remove any choice this is how you can do so on incident form remove closed option for the idle user now this will remove that closed option they will not be able to see that closed option and that's what you have to do remove options save now on client if you really want to save the form with some action of the user maybe if he changes the button he changes the field basically in that case you want to save the form without clicking on save button in that case you can use this and you can save the form in that case you have to use dot generouscoform.com the next is set disabled so if you want to make specified field available or unavailable so you don't want to show that field in that case you can use this set disable like you have the visibility of the field in uif policy so it's quite similar but the recommended option will always be ui policy rather than client script set display now you will be able to display the fields now disable is quite different because you want to make that field available or not then you will use disabled and if you want to as part of the display when whether you want to make that field uh visible or not that you can in that condition you can use set display so gee underscore form dot set display and as a parameter you can put field name and you have to put the boolean value comma like comma boolean value uh that is true or false that's what you have to mention set label off now as we can get the label of the field you can also set the label of the field so you already have a label uh on the form but it might happen that your customer might look for some some different label with some another condition in that case you have to put that condition and then you have to put as set label off and in that case as a parameter you have to mention the name of the field and then you can set the label set mandatory so as i mentioned earlier with the help of ui policy you can set the fields as mandatory visible or read only but you can also do it with the help of client scripts and this is what you can do that is set mandatory so if you want to make any field as mandatory you can do it with the help of g underscore form dot set mandatory and the field name and you also need to mention mandatory whether it's true or false whether you want to make it mandatory or not that's what you have to mention the use case which i have mentioned here when form is not the new ci uh should be mandatory so if form is not new the ci should be mandatory that's what it is telling and how exactly you will find the form is not new that is is new record method set read-only it's it's similar which we talked about with the ui policy you make read-only and you can make it with the help of set read-only g-underscore form dot set read only set section display now as we talked about this sections of all the forms we have if you want to make them display if you want to display those sections as per some conditions then you can use the set section display and it will also take some parameters that is section name and then the boolean value the boolean value which i'm talking about the overall parameter would be the the section name then comma and then you have to put the boolean value whether true or false whether you want to display or not set value now this is really important method of client script so as a use case you can see we have on incident form set the value of current logged in user in caller field so you want to set the current logged in user in the caller field because automatically it doesn't come so let me show you in my personal developer instance so if i click on create new and form is getting loaded but now you can see it is asking me for the caller now if your requirement comes in that you want to push this caller automatically the whomsoever the user is logged in so in that case i will go to my client script i will create a variable because i have to get the user first whomsoever has logged in and i have to get the sys id of that user in that case of what i will do i will create a variable user and i will do jnscore user not gender score form now g underscore user is also another really important api which we will talk about in our follow-up session so we have g underscore user dot i will select user id i press tab semicolon and here i will put gnscore form dot set value i will put the name of the field we have that is scholar id comma and here i'm going to put the value which you want to push and that is we have saved in user variable i'm going to click on save i'm going to my incident form saving the reloading it when i'm reloading it you will see that caller now has system administrator that is me i have logged in as system administrator and that's is it is showing my name over here so you might get this requirement in one of your organization or one of your requirement from your client or from your customers then we have show error box this is also another method that if if you want to show the error box then you can use this particular method so if you want to display an error message and under specified form field as a box under the field basically in that case you can utilize this show error box the the parameter which is neats is the name of the field that's what you have to mention and the message you want to display so it is it is not similar to add info message or add error message because add info message or error message they're not related to any field they just show those messages at the top of the form this is some somehow related with the field level so if you want to show some some kind of box or message on on the field then you can utilize the show error box show field message show field message is another method in which you can use if you want to show some field message it will again come like in box so if you want to show some message on the on the field then you can utilize this particular show field message show related list we already talked about highlighted list hydrated lists and similarly we have show related list it's vice versa so if you want to show related list then you can use and you have some names of the related list in that case you can utilize gnsco form dot show related list and then you can put the name of the related list submit this is another method when you want to perform some action you want to submit the form in that case you can utilize this submit method so if you want to save the record you can use this particular method that means gee underscore form dot submit now this particular submit method it it some you can utilize it with parameter and without parameter as well if you will put without parameter if you will keep put this method without parameter that it will just save the racket but now if you will put the ui action if you want to click on any particular button so if you want to perform the ui action is specified by the in the parameter then you can use that particular so that that action name you want to click that that name of the ui action button you want to click you have to utilize that so while user is doing something and on some condition on the client you want to click a button or click a ui action in that case you can utilize submit g underscore form dot submit and the name of that particular action in that case you can utilize submit so these are the all g underscore form methods in client scripts you can use the follow up session we have will be around g underscore user that session will be really crisp and small because we have a lot of methods for this particular api g underscore form but g underscore user we have only i think uh small number of uh methods so it won't be that much long so these are all important apis we talked about this particular topic in our last video there was part five we talked about common api and methods used in client scripts and the discussion we had was about glide form that was our first topic now in this particular video we are going to talk about glide user that is the second api we have used and and that's what we use in client scripts so let's take a look at how exactly you can utilize uh glide user in your day-to-day development this is my personal developer instance let's go to incident application i will go to here open and then i will just go to client script i will click here go to client script and click here and i will create a new client script so client script form is loaded now i will just give a name like demo for glide user so we have already talked about glide form but in this particular session we are going to talk about glide user so i have incident table already selected type i will select onload for now and have this onload function right here so now i will show you that how many api methods we have for glide user so if i type g underscore user now this is the object we use for glide user so if i have this gnscore user if i press start so now these are the methods we have for glide user so you can see we have like first name get client data get full name has role now i will show you the utilization that what kind of data you can get from from all these uh methods you have for glide user so if i start with first name and how exactly you can get these values so in order to show you what i will do i will do g underscore form basically so i will start saving the data first so let's create a variable variable a and i will use gnscore user dot and this is the first name now if i'm going down and if i put here alert and i just put here the the first name of user is and that is plus a so i am saving this i'm just putting the semicolon and i'm clicking on save now let's see what exactly it does so you have this gnscore user dot first name if i open any incident and i go here now as you know this will run on all the forms that means that will be that it will run on on load basically every time form will load whatever condition it has it will show it so now you can see it says first name of user is system now how it is picking the this particular first name now i am the current logged in user so if you want to populate current logged in user's first name then you can utilize this method let's take another example so i'm just making it as an as a comment i will create another variable i will put gnscore user dot this time i will put get full name and it says returns the first name and last name of the current user i press tab colon and i am just saving the form and just to show you in a home like this is how we have the scripting i just made like a full view basically now if i go to my form again and i reload it you will see the different value now you can see it says first name of the user is system administrator you can definitely change the verbiage we have right here now it is showing the current logged in users complete name then we go back to our scripting now let's comment this as well this time i will use other method so i have gender score user dot now we have this has role so it says returns true if the current user has selected role or the admin that means if this user has this role so what we will do we will put this i can put the role which we i'm looking for maybe for example idle and i can put here if a equal to true so if a equal to equal to true then it should show the first name of the car is that's what let's see what value we get the value of variable if i save this and i'm just reloading great so that means it is returning the true that means this system administrator has idle role and if you want to confirm what we can do i can go to the profile as of now it is self-service view i will go to default view i go at the bottom so it has admin role so it is returning as i mentioned that basically it is not searching for the itil role basically we mentioned so it doesn't have idle role but it still has admin role and that's the reason it is returning true but what if if we if we mention uh maybe for a user who doesn't have admin let's let's try with any non-admin user so if i impersonate just an idle what do you think should it show that alert so let's take a look so if i click here open any incident like a similar incident we had yep it says value of variable true now the reason we are getting this particular true alert because this user has idle role but let's see if any user who doesn't have idle role so what i will do i will just go to system administrator impersonation again i will try to search for a user who doesn't have admin role so maybe apple tutor yep apple tutor is just like a self-service user he doesn't have any kind of uh like item rule or something so what i will do i will impersonate him this time but if i will do that he will not be able to see the incident so you might select any other role so let's do one thing if i go to my client script so this is for demo for glide user client script so as you know if it says if it has itil rule then it should show that it is true and you can put any role you want that's how it works that's the reason even for that itel user we impersonated it it showed as true now let's comment this one and try to create a new one we will have where a equal to gnscore user dot this time we have has role exactly that means returns only true if the current user has this specified role so it will check that this user has that role or not so maybe this time we will put has role exactly and we will put like maybe project manager or maybe knowledge let's let's put that knowledge role but i should not make it as comment now it should check whether the user has this particular role so if i have this if a equal to true let's make it false and alert the user does not have knowledge role so we should definitely get this message even you are an administrator because you don't have knowledge role so i'm going here i'm reloading the form and yes we are getting that alert now let's try to impersonate a user who has this role so in that case what i will do i will go to role and i will search for knowledge role so this is the role we have and i'm just checking the user who has this role so we don't have that option but i can add it i can add the related list as now it is showing me the users who has this role so this problem manager so let's try to impersonate problem manager so if i impersonate problem manager i have this incident i click here now you can see i did not get this alert message and the reason behind it because i have that role and that's the reason it is not showing me that alert this is the difference i just wanted to show you that how exactly it is making the difference and checking the value that whether that particular user has that role or not so if your customer has any requirement which is somehow related that they want to check some kind of roles or with that roles they want to have some other conditions or some actions or some messages they want to display you can do it with the help of g underscore user so i will go to client script then we have other methods as well let's take a look that is gn score user dot now you can see we have has role from list now this is something you can put the list of roles you want to check and that's what it is showing returns true if the current user has at least one of the specified role in the comma separated list or admin role so or admin role will definitely be there so if the role which you want to check if user has that role or not then the next we have is has roles now you have self-service users who don't have in any kind of rows if you want to check it then you can check with this particular um method that if the current logged in user has any single role at least a single role then it should it should return true and then you can utilize that value of true as per the logic or conditions or situations you have as per the requirement then we have last name so as we we were able to get the value of first name you can also get the value of last name then we have user id the user id will give you the society of that user record so let's take a look so this time i will put user id so i have this user id i press tab and i will mention here i will just remove it and i will do sis id of current user and that will be plus a and i am saving this but before seeing the result let's check the society of this so if i go to my profile it says copy society i'm copying it and i'm just like saving it for now so you can see it starts with six eight one six and with four four one and i'm going to the incident form i'm reloading it now you can see we were we are able to get the same society so if you want to get the society of the currently logged in user and you want to utilize it in any of your scripting then you can use generscoreuser.getuserid now if i go back to my scripting and then we can check if we have any other method then we have just user name and this would just return the username and that is also the part of your user profile so if you go to the user profile and just select the default view so this is what we have user name the label is user id but the name of the field is username now if you want to get the username of the current logged in user then you can get it with the help of get user name so this is all about the g underscore user that means glide user api we have inclined script in this video we are going to talk about debug client scripts now as of now you have learned how to write client scripts what kind of methods what kind of api you use in client scripts now one of the important factor of a developer or performing a scripting is debugging because it's not mandatory that every time you write a scripts it gives you the exact expected results and sometimes it might happen that when you are writing a code maybe of 20 or 30 lines and you're not getting the expected results in that case you have to check that why i'm not getting the right results in that case debugging is the best way to find out the basic reason that why your script is not working what are we going to learn we will learn about the tools for debugging client scripts that what are the tools involved so when you write client scripts and if you want to debug what are the tools you can utilize to debug client scripts and then how to debug client scripts it just we will show how you can utilize these tools for debugging client scripts so the tools for debugging client scripts now as you can see we have mentioned four tools let's start with the first tool we have that is javascript log so servicenow provides you a method where you can use that logging and then check whether your scripting is working fine or not then we have field watcher then we have response time indicator that how you form is responding how how like how exactly is scripts are getting loaded how much time they are taking that's what you can do and then we have try and catch off javascript now try and catch is is not something invented by servicenow it is the global used javascript uh like methods that's why you use try and catch the first tool we have is javascript log now as you can see on the screen this is our incident form but at the bottom this is a new screen which i enabled so there's an option which i will show you in the practical session just later on so you as you can see we have this javascript log now this window or this section shows you the all the logs running on this particular form now what if if you want to uh check uh you your code maybe that's written in maybe 30 line of code and you want to check whether some part is running or not in that case you can use the javascript method we have provided by servicenow and that is js log so if i go to my next slide we have this how to write a javascript log that how can you show that log in in servicenow for client script and that is js log so js lock is a method which you can utilize to write the javascript log and check whether your script is running or not the next tool we have is field watcher now in the same section of javascript logging we have another tool that says next section we have field watcher you can see we have this incident a field incident form opened and you can see we have all these elements where you can check different scripting you have in service now like you can check acls workflow activity business rules client scripts data lookup data policy but as of now just to show you i have just selected client script and for other functionalities you have like acl business tool you will see in a later section of servicenow developer training then we have response time indicator now service now has created a section at the bottom of the form like every form or every you have you will see this in your native servicenow platform ui that it shows you the response time now how you open this so if you will open service now form by default that you will not be able to see the exact what you can see on my screen in red section but there will be a watch over there so you can see that watch which is highlighted in blue if you will click on that watch then it will show all these details like response time that what is the network how much time you're getting and then server time and everything you have this is in milliseconds the time which is mentioned the numbers which you are seeing those are in milliseconds and if you will put your mouse in this particular section you will see some more details and we will see it in later section and the fourth one we have is try and catch that is not something invented by servicenow that is the global which you use in javascript even if you're writing a javascript apart from servicenow you definitely use try and catch for debugging so let's take a look at how exactly you can utilize these tools for debugging client scripts in servicenow this is my personal developer instance now as we talked about our first tool that is javascript log so if you remember we showed you on the screen that with that section which was on incident form so let me show you how exactly you can enable it so if i open any incident form i have this incident form and i go at the right top we have we have the settings button if i click here you have to go to this developer section this click on developer tab and you have this one called javascript log and field watcher if you enable this you will automatically see at the back end that this has enabled so i will close this and now this is open now we have to talk about javascript log so this is that section now here you can do that scripting and put that method that javascript log which we talked about that is js log that will show right here so let's try to do some uh debugging with the help of jslog method so currently we are on this screen as of now i'm just closing this i'm going to create a client script i will create a new client script and this will be demo for debugging i will run it on load now let me show you how exactly that log comes so if i go here and i put js log and i put like this this is the demo of client script debugging i'm just saving this now if i open my form i'm click here now as you can see we have put it on on load i have loaded this form and if i enable it so let's let's open in the same window i am opening it i have enabled javascript logging and now i am opening the incident so i have opened the incident and if you will go at the bottom so form was loaded now you can see we have this this is the demo of client script debugging and let me make it large now you can just ch like resize the window small medium large if you want to delete the logs you can click here it will remove all the logs and what if i reload it again now it's loaded but your log which you mentioned in your method it will be right here yep we have this this is the demo of client script debugging this is not just showing just for one lock it is showing every javascript log we have that's what it is showing it is also showing that we are we are running on load this particular script that's what it is showing all the client scripts is running so this is how you can check the logging for any kind of coding you're doing in your client script and in that case even if i go to my client script again and this is demo for debugging and let's try to write like gs dot or maybe general score form dot add info message this is first phase so you can write like this this is first phase and i will put like log message then i will put here g underscore form dot now it might happen that by mistake you have put in the wrong method like i have just removed e letter and i'm just writing that log message this is the second face now let me remove this for now and i'm putting the semicolon and here as well and i'm saving this now as a developer you can see that it is not giving any kind of error message to me even i have removed that e from my method so as a developer i might do some mistakes now let me run this and see if it is working so if i go to my form it's running on load now you can see it says log message this is first phase now this is running just the first one not the second one now what if if you have multiple lines as of now just a demo i have shown you that i have written only two lines but it might happen in your client script you might write uh 20 lines or 30 lines and they can be some different functions or different sections as well maybe if else statement multiple if else statement how would you find out that which section is running which not so in that case what i will do i will go to my client script i will divide my scripting in sections so i will put js log here just to check if it's running and then i will put log message for first faith and i'm right i'm going to write this for second section again gs log log message for second phase now as you know script always runs line by line it will run this this this and then this so let's save this and see the results so i'm going to my incident again opening it it's running but i will enable javascript log i will remove some everything and then i will reload it i'm reloading it so it's showing me the first result which we have mentioned as add info message and it says log message for first phase but let's check is it showing for second phase absolutely not so as i mentioned it is failing at the basically on the third line on the third line of scripting and there we have some problem so in that case what you will do you will go back to your script you will go to your script open it and check okay this one is not running that means there is some problem with this particular line so i will check it again and i will see okay i have not written this e i will write e here i will save it and then i will remove everything and i will go to my incident form again remove and load it this time you can see both the methods are running and even the logging methods which we have are also running so this is how you can debug your client script with javascript log so js log is a really good tool to use good method to use for debugging client steps field watcher is another tool for debugging client script it displays the information about all actions performed by the system on selected field so you can understand with the naming convention it says field watcher that means it watches the field which you have selected and shows you the information whatever action is being taken on that particular field now in order to enable field watcher what you need to do you need to for example if you're watching any field and you want to see what kind of action is happening or if you are doing something or you have written some client script or you want to see whether what action is being taken on that particular field so let's select this one so you have to right click on that field at the bottom you have this watch priority so you have to select this watch once you will click on that watch priority it will automatically enable the field watcher as of now client script is selected so let's reload the form and see if something happens if i'm reloading the form as of now it is not running anything but what if i change something as per the priority so let's change the priority i'm making it as high and you can see i i changed the impact it automatically ran this client script if i have this one i have this alert which i wrote a client script i'm clicking ok and this is showing the change of value now as you can see this information in this particular screen now what exactly uh what kind of information is showing this is the time stamp then this is the action taken that means what kind of action is being taken when you are changing or whatever action being taken on that particular field then you have caused by that due to which client script it is it is being uh like doing or this action is being performed so that is this client script and then we have old value to new value so if you remember you had this three and you made it to one then you have urgency three to one but now you have this one and that is what it is showing the change of value so what was the old value and what is the new value and if you will open this particular section you will see the different client script it was trying to run so it was running this one this one every every client script we should run at the end we have this work notes mandatory on change of priority and that is the reason it is showing because if priority is changing then work node should be mandatory and it is mandatory so in this case if you have written any kind of client script on this particular field then you can check it whether it is running properly or not so this is the feature of field watcher debugging of client script the next tool we have for debugging client script is response time indicator response time indicator is really useful to check if your page is loading slowly or not it shows you some details about network time server time and browser time now how exactly you see response time indicator on any form view which you have in service now go at the bottom if you go at the bottom if there's a clock here if you click this clock it will show you the details and it says response time and all the timings which are showing here it's milliseconds so it says response time is nine eight milliseconds and in that you have network it's taking three server two six five nine and then you have browser is taking four three six milliseconds and why it is taking a lot of time because when you are on cloud first of all and you are getting all these data all the content of the forms from servicenow cloud now all these three sections we have like network because first when we will load the form it will go to servicenow cloud get the data and how much time it is taking to get that data so it says three milliseconds then you have server now from server it loads all the files or all the contents you have then you have this two six five five nine milliseconds and then you have browser that means browser will show it make that content in browser that will also take some time to load all the files we have at the back end so if i just for example if i click here again and i just put my cursor on this particular clock you can still see the same information but if you will click here it will show it will expand it and show you the right results and you can see it says like uh colors like in red it says network then you have this server and then you have this browser so all three different colors now this is also one of the way because if you are showing the form to the end users that means they are working on the client side they will definitely do some action at the back end that it would serve aside but client side is really important because that is being loaded on the user's screen on users browser so if you will write multiple client scripts then it will definitely hamper the performance of the user form basically any form if you are writing multiple client scripts on incident form then it might impact the performance because when page gets loaded it loads all the scripts which you have written it will try to run every script you have written on the client side so you have to see and this is how you can see that if you're getting really maybe high value of these milliseconds then you can check whether is there any client script which is hindering the performance of any form you have in servicenow so this is all about response time indicator the next tool we have is try and catch that is not provided by servicenow this is a global method which is being used by javascript in javascript there's a method which we can use for runtime errors if you want to catch the runtime errors that you can get with the help of try and catch let's take a look at how exactly you can use this in your client script so we are on incident form i will go to client script i will cancel this and i will go to client scripts leave we have this demo for debugging so we have this if new value alert this if not so what we can do now it might happen that you have some errors in this scripting now in order to save that what we will do we will try to handle the error and we will put it into try so we will try this section that is if new value is equal to equal to 1 and we will catch er that is the error and we will put here js log log message we do have an error and i will put the error value here which we have just created over here and that's it now i'm going to save this let me go to incident form and i can open the javascript log as well i am changing it to p1 so we are running this now you can see we are not getting that log because the first line that try it is running without any issues now what if if we definitely have some issues in that scripting in that case what i will do i will go to my client script i will close this leave and i will close this section this time i am making some error now it is not giving me any error as a syntax it might give but this is the javascript syntax so i'm just writing allah now this should not run and if this should not run that means it should give me some error and that's that's the reason we have written this catch so i will save this i will go to my form i will close this and i will reload it i will change the value yep we got the error and it says log message we do not have error reference error alert is not defined what error you are getting it automatically shows ho over here now this is the best way to debug so when you were writing the script you didn't know about the mistake you did because you you were using uh rather than alert you were using allah but you don't know you as as a developer when you were writing the script you are not aware of it but what we did we just check with the help of try and catch that try this scripting if it doesn't work show me the error and that's what you get at any catch and that is what it is showing you and this is how now you can go back to your scripting as a developer if you got this error you will close this it will go back to your script and check where we have this error it might happen that you have written a 30 or 40 line of code so you can check which error it is giving and you can find it so i have this other and i will just put t because i now i know that i have written it in the wrong way and i will just save it once it is saved i have corrected my script now it will again run try not the catch one because it is it will run without any issues it will not give any error if try gets failed then only it will go to catch and shows you the error message so this is how you can use try and catch method for debugging client scripts in this video we will talk about ui policy you must have learned ui policy in your administration training but in this training we are going to talk about that how can you do scripting in ui policy and why exactly we need to do scripting in ui policy what are we going to learn in this session we are going to learn about what is ui policy scripting in ui policy and then creating ui policy i will show you some examples that how can you create ui policy as per the requirement you get from your customers and from your clients what is ui policy ui policy is used to change the behavior of information on the form it runs at client side it is primarily used to make fields read-only visible and mandatory on the form now what is the important thing which i can tell you that with madrid version and i if i remember they came up with i think london that now you can also make related list visible and hidden that's what they came up with so as of now the only action you could take is read only visible mandatory but they came up with a new feature that you can also play with related lists if you remember in our client script we had a api method in which we could use uh and hide and show related list but with the ui policy you don't have to write any scripting and you can use uh in ui policy and we will see it further no scripting is required now one of the important thing uh of ui policy is that you don't need to write scripting majorly for these three functionalities like if you want to make something read only on the form or visible or mandatory or the fourth thing which i mentioned the related list but what if if you have some any kind of a complex complex behavior or maybe kind of kind of a complex condition in which you have to do a scripting and ui policy so that's the reason it's written at the at the bottom that advanced changes required scripting how to locate ui policy so in service now if you will go to application navigator under system ui you have this ui policies and the form which you can see on the screen this is how this ui policy form looks like scripting in ui policy scripting and ui policy enable a developer to create complex conditions and execute advanced behavior any behavior addition to configurable functionality needs scripting so for example if you are making some fields mandatory or some read-only or visible and in the same condition you have some other situation which can only be done and you do that is apart from read-only revisible or mandatory then in that case you can utilize a scripting in-service now for ui policy and as you can see on the screen this is the screenshot of ui policy where we have a section called script and there you can write the scripting out-of-box ui policy now as you know when servicenow has developed this platform they themself came up with baseline functionalities that means whatever functionalities they have it might be client scripts script includes ui policies business rules they come up with some baseline functionalities of all these sections which i am talking about so they also have created ui policies and if you would see i just took this screenshot from the current baseline which i have like madrid version so as of now they have created 1386 so if you are getting serviced now it might increase as per the enablement of the plug-in but as often as a baseline they have this 1387. it might increase as i mentioned as for the plug-in or any functionality you enable so these are all baseline ui policies now it might happen that your customer or your client sometime can ask you that hey i do not want this kind of feature and that feature might be working with the existing ui policy so in that case you might need to disable that ui policy or you have to edit it or you have to create a new policy so it's totally depend as per the situation and as per the customer requirement you have how ui policy works with scripting now as you know when you have learned in your administration training that when you create a ui policy there is a trigger section and that is when to apply that means you will put some conditions then when exactly you want to run this ui policy now same thing you have to do in your scripting part as well and you can put some scripting conditions here and then you can do the scripting so as you can see we have when to apply there you can put the conditions which will run once that condition will met and then you have to go to the next section that we have script and there's a check box called run scripts so it will not automatically show these scripting fields once you will click on that run script it will automatically show these fields like run description ui type then execute if true execute if false now what exactly it is showing that if you have this ui policy and you have mentioned some condition in when to apply if it mets then what it does then it will see the scripting which you have mentioned in true part and in false part if the condition doesn't met then what it should run if you have that situation and if it mets that what you have to do that you can mention in both the fields so let's take a look and see the practical example that how can you create a ui policy and how exactly it works with scripting so let's take a look this is my personal developer instance now i will show you how to create a ui policy with scripting so if i right click on the form so currently i am working on incident form so i'm right click on incident form i will go to configure and i will go to ui policies if i click here ui policies it will show me all the ui policies written for incident or maybe on the task because it is inheriting the incident table is getting inherited from task table so what i will do i will go to new so here we have a scripting and we have this when to apply now let me give you the situation that means the use case so the use case is what if if the priority is p1 then short description should be mandatory but at the same time it should show an alert at the top of the form now servicenow does not give that direct functionality so that like that means without scripting with ui policy because with ui policy you can only do visible mandatory uh read-only and related list which we talked about so let's show the message so uh description description as or make description as mandatory and show message so if you remember in client script we had that name but here you don't you just have to write short description so i have this table selected incident this is active it is we're working on global scope for scope i will have a different section that why we have this application scopes and how servicenow came up with then we have this when to apply now this is the trigger point we were talking about and the trigger point which we are talking right now it's priority if priority is one if that's critical then i have to do this so i will save this first and then i have this ui policy action in the related list and then i also have ui policy related list action and if you want to do something with related list but now we will just go to ui policy action i will click on create new so i have this new button i will select the field name now which field we want to make as mandatory so we already talked about it that will be description and that will be mandatory so i have this true and then i'm going to click on submit now as you know i have to do it at the same time so in that case i will go to scripting i will check box this particular field now if the priority changes to p1 so that means i want to show that message when it's true so i will write here what i will do i will do g underscore form dot add info message you are going to make a p1 instant i just mentioned as info message right now now you can see i have utilized the similar what we used in client scripts because ui script ui policy runs on client and that's the reason this gee underscore form this is the api for glide form is an api for client-side scripting so you can definitely use it so whatever uh api we have for client-side you can definitely use it in ui policy as well majorly like glide form glide user and g underscore scratch pad we will talk about it later that for about gender score scratch pad but as you saw the examples which you worked upon like gender score form and gender score user you can utilize both right here let's let's use gnscore user as well so that you can understand better so we will have uh g underscore user dot um i will put full name and i will put it as an alert so you will understand that in what situation you might need and the reason i'm showing you with uh mandatory because in that situation only you will utilize this and servicenow always recommends to use ui policy uh before client scripts i think most of the things should be done by client script is if it is exactly related to client and you have to write the scripting in client but if something is related to ui policy where you are making things mandatory at the same situ same same time you have to do something else or maybe some other conditions or behavior in that case you can use uh ui policy scripting so i have given this uh i will just save this i will go to incident form i'm opening this now we have this impact and urgency so what if if i make it one and i make it one now you can see it is showing me that alert first and if i click ok yeah you can see the description becomes mandatory at the same time it is showing me that message which we added that is you are going to make a p1 so that means it is working so you have used scripting in ui policy so if i go back to my ui policy and go right here i will try to maximize zoom the browser so that you will see it better so this is the scripting we we have written this one and this is the function which automatically shows when you select this so you don't need to add anything and what exactly it is doing it is just fetching on condition that means the trigger value which you have given here so this function is automatically fetching the value that is is it is it uh basically the condition which you have given has it he met yet or not that's what it checks so this is how you can create ui policy there are other situation there they might they might be some different use cases from your customer but you are as a developer you are the best person to decide whether you have to write scripting and ui policy or not but as i mentioned in most of the cases like as we learned um like in client scripts we had some apis which can also make fields mandatory visible read-only but you should not use it i would say like i would definitely recommend that you should not use them because if servicenow has already given you this ui policy which can be done without scripting but if you need to have some complex behavior or advanced behavior then you can definitely use scripting so this is overall i think ui policy is like a small topic and and mostly people don't use it but it can be used but in some situation not every situation so uh this is how you can create ui policy in this session we are going to talk about business rules business rules are the really important functionalities in servicenow i would say as a developer you would definitely need multiple times this functionality your client or your customer can come up with different functionalities and you will always go for business rule it's not something you would always go i'm just telling you the situation mostly it happens that you will definitely create business rules because this is something which plays with the data with your database and that's the reason you need this business rules what are we going to learn we will talk about what is a business rule how business will work creating a business rule then scripting in business rule this is what you are going to learn in this particular session so once once you will watch this session you will be able to create and execute business rule in your servicenow system and if your client your customer has given any kind of requirement and you you can definitely decide whether that requirement should be fulfilled by business rules or client steps that you can take the decision so till now we have created client scripts and ui policy those were related to client-side scripting but now we are talking about server side scripting that means now you can decide once you will watch this session then you will be able to decide whether you have to write client script whether you have to write ui policy whether you have to write business rule business rule the first question when we talk about business rule is what is a business rule and that is the really important thing to know so the service side script that runs when record is displayed inserted or deleted or updated or when label is queried this is what business rule is it's kind of a script which runs when these operations happens so whenever you are inserting updating deleting or you are hitting the table or hitting the database in those conditions in those operations if you want some actions to be taken in that case you will use business rule because this script run during that time it is used to change values in the fields when specific condition in is met so if you want to change some value while inserting the data while updating the data while deleting the data or maybe if you're acquiring you want to do some action in that case you will use business rule the important point is it runs on server side as we talked about earlier ui policy and client scripts they run on client side but here this run on server side it runs with all the ways where record is accessed like list form or web services now what it means if you are updating the data from list view or you are updating the data from form view or you are updating the data from web services or maybe you are creating the data you are inserting the data or you are updating the data from web services or deleting the data in that case business will will definitely run locate business rule now how you will find out this business rules in your servicenow system so under system definition application menu you have a module called business rules once you will click on that business rules module you will see the list of business rules created in your service now system if you have just bought or just have a new instance then you will see all the baseline or out of the box business rules which have been created by servicenow business rule form now before creating business rule it is really important to know what art fields it has because without knowing the business rule form and feel you will not be able to create it that what field is required when so the first field we have is name of the business rule and that's the name field so if you are creating a business business rule and you want to recognize then you can use the the name field and you can put the name and just to give you a suggestion if you are working in your organization whenever you create client script ui policy because you already have a baseline business rules or these functionalities from servicenow i would recommend you to always start the prefix with your organization's name whatever organization name you have just put it acro as kind of the acronyms in the beginning as a prefix so that you can recognize in the future that which one is out of the box and which one is uh created or customized by uh your team that's what you can recognize so the next is table now table field where you want to run this business rule so we have multiple tables in service now like incident change problem now you want to perform that operation you want to take some action on incident table then you can use and you can select incident table here or any table you want where you want to run the business rule or you want to run that logic which you are looking for or which your client has given then you have application this is just a scope of the application as of now it's global so for example if you have any customized scope then you it will just just run in that scope but as of now it is showing global scope or it shows you which scope you are in then you have this active and inactive business rule that means this check box tells you whether you want to activate this business suit or deactivate this so if this checkbox is checked that means it's active it's not checked is not active then we have advanced this just enables the advanced sections advanced functionality with scripting so if you want to do scripting in business rule then you have to enable this particular functionality by checking this box now this is the really important section of business rule and i say the business rule form as well and that is trigger of business rule now your business tool will not run every time you have to define some conditions it might run every time but if you will put some conditions that it might not so this is the trigger point of business rule and that's the reason the section's name is when to run so that as a developer you can define when exactly you want to trigger this business rule so the field we have here is insert or update so when to trigger on update or an insert so if any user is inserting the data do you want to take some action if user is updating the data do you want to take some action in that case you can run this business rule now the important point here is if you will select the table for example incident and if you are selecting in insert in that case and you are just saving this business rule then please remember it will run that business rule every time and don't think that if you're not putting any action that means even if you're not putting any action and if you are just running this business rule then you are taking some or you are degrading the performance of your system because you are utilizing some resource because business rule will also take some time to run so that's what we have this is the operation where you can select what kind of operation you want when that's what you selected here so if user inserts some data or user update some data or maybe both so you can select both then you have filter conditions that means condition after insert or update operation so if you are inserting the data but you don't want to run this business rule every time you want if the state is maybe new or maybe short description is not empty these are some conditions and this will be decided as per the requirement you have from your customers then we have role conditions now here you decide the role of the user who generates that event basically so user should have that mentioned role so if there's a business tool which is specifically for particular role and if the logged in user does not have that role then you will not run this rule then we have actions so we talked about as of now when to run the business rule now once you have decided when to run and that condition has met now what exactly it should do that you will decide with actions and out of the box we have the set field values add messages and then abort action so the first field we have is set field values as of now you you're not able to see uh what values you can select it will be visible once you will select the table then you will see more option you can see the list of fields and you can also select the values what value you want to put then we have add message this is something methods to be populated during the action if you want to show a message to the user while he's doing that action maybe he's updating the data and the condition has been met and you want to show something in that case you can check this box it will open it will show a new field and there you can mention the message you want to display to the user then we have abort action now this is the really important feature of servicenow platform by via business rule now you can't you you must have some conditions where you can't allow every user to uh take some action every time without uh without some uh maybe uh data validation in that case you can do this about action just to give you an example that if you have incident table or maybe any other table which are saving some records maybe employee name now what if if user is filling their data and they are using the employee number similar which is already there in the record so you want to stop the user that hey it seems like this number is already there in the system so you have to select the another employee number in that case you can abort the action of the user so user is opening the form filling up the data but he has selected some same number he's hitting the submit button once he's hitting the submit button it will check is is it con meeting the condition yes that means that number is similar in that case you can abort the action and user will not be able to create the record at that particular time he has to open the form again and the create the record again then we have this advanced check box so as i mentioned when you check this check box it opens up the new functionality some some hidden functionalities and also give you the opportunity to do scripting in business rule so we have this when order delete query these fields if you remember they were not visible in the first go when this advanced checkbox was not checked but now it is checked so you can see these new fields and if i talk about these fields the first option we have is when now as we already saw the oral section is when to run now this is also really important field that what when exactly you want to run this business rule and that says the features the the function choices we have are before after async and display these are the choices and as per your requirement that when exactly you want to run this business rule you can select these options and when the next field we have is order it's just the sequencing for running the business rule so if you have uh if you have like multiple business rules and you want to run those business rules with some sequence and you don't want all the business rules to be to run every time then you can select this order then you have delete the record now this is a similar as we had insert update they are the operations like database operations so similarly you have this delete because user might select delete because they might delete the racket as well in that case you can you can put this and and if user is deleting a record and you want some action to be taken then you can select this particular field and you want all of them then you can select all of them then you have query now if you click on a module which shows you the list of incidents it's similar the query you are doing so what if you want some kind of a check when user is squaring the data in that case you can utilize this query as an example if i click on incident and i do want some specific users to see all the data in that case you can put the query and you can put the condition that's what you can do here or maybe you can put some action as well whenever i am hitting the data when i whenever i am querying it maybe i see a message it's it's totally up to you as per the as for the condition as for the requirement you have and the last section which is automatically enabled when you check this box advanced check box is scripting and it will have two fields one is condition and then script in condition it's similar to the script condition you have to mention here maybe whatever condition you have that's what you can mention here and then you can write the script in the script field now as you learned about how this business rule forms looks like how fields work what are their usage now the next topic is really important to learn that how business rule work how exactly they they they get executed as you saw some of the sections like when to run it's quite similar and then what action that business rule has to take it's quite similar that how exactly it works but i will explain you a little bit in details so the first thing is we put when to run so when whatever whatever conditions you have put in invent that's what it checks that do i need to uh do i need to run that business to right now or have i met the condition yet that's what it will check as per the operation so first if you have checked the insert operation for example first this will check the operation once it is checked it will see okay i have inserted the record it seems like there's a business rule which is written on insert on the same table i will check what is the condition and that is when to run once that condition has been met it will check what action i need to take once that action is checked then it takes that action in that particular table and that's how your process works starting from the operation to when when to run and then action and then action is taken so the first is trigger point so you are triggering the event and that business rule as per the operation user is taking then you have action it checks what action i need to take once it is decided yes that action i need to take then it takes that action and that is action taken on that particular table so this is how business rules work let's talk more about when to run business rule so as you saw there's a functionality when you check that advanced check box it shows you a field called when which decides or which checks the timing of running of the business rule that when exactly this business rule should run so as per your requirement that's what you decide whether it should run after whether it should run before whether it should run async or whether it should run display business rule so let's start with after business rule now after business rule execute after form submission when form is submitted and record is updated in the database so if you are you are an end user and you are creating a record you have opened the form submitting the incident once that incident is created then it this particular business rule will run that's called a timing of this particular business rule as an example if you want to copy some fields from parent to child after insertion after the data is inserted into servicenow record is inserted in servicenow incident table and you want to copy in that case you can use after business rule before business rule before business rules execute when form is submitted but before record is updated in the database now that's the difference between after and before so when form is submitted form will we will be uh user will be submitting the form but that action which we want to take we want before creating it and it's similar like a bot that you want to check you want to check something before it gets inserted so if i'm filling up the fields in servicenow incident but i want some validation and if that validation does not met then i am aborting some action or even it's not metting i'm maybe i'm putting an alert for the user that is what it does so before creating or updating the racket in the database you and you want to have some action that's what you utilize before business rules it's similarly like that if you are um creating an incident and you want to auto populate any incident any incident for example i can give you the right example like open buy ideally from service now open buy is already there so you don't have to do it but i'm just giving an example if you have some other field maybe for example a reported buy you have a field on on your servicenow incident form that's uh reported by and as an end user uh when you are submitting it and like you'll be happy if you will see your name automatically so when i'm filling the data i'm clicking submitting the field it will automatically show my name over there it's just an exam example idly you would do you would you will always ask users to fill that data but if user is not filling the data then you can put himself or herself that's what you can do with the help of business rule then you have async business rule now this is also another kind of business rule now this business rule runs after records are inserted modified or queried so it's like scheduled jobs basically it's it's a it runs asynchronously so it isn't it doesn't have that synchronous job it's it's like a scheduled jobs and where exactly you can utilize it like when when exactly you will decide okay i should write asynchronous business rule so maybe if you want to notify some users then uh like when cis are affected by any incident in that case you can you can write async business rule or maybe you want to do some sla calculations it's similar like a scheduled job so in that case you can write async business rule but mostly if i say you are mostly write before or after business rule in service now as a developer but you would definitely get the requirement for async business rule as well and then we have display business rule now display business rule runs when data is read from the database and before presenting to the user so if you are uh creating uh or inserting an uh incident if if you are creating an incident and you want something uh to be uh like read from the database in that case you can use display business rules now display business use uh business tools is mostly used with g underscore scratchpad that's a different global object it's a variable which is used in uh business rules and why exactly you use it because if you want to populate or fetch some data from the server to the client side in that case you use g underscore spread scratch pad what operation so as we learned about when exactly you are going to run business rule as for the timings before after async or display business rule but you also need to decide that in what operation that business rule will run that what kind of operation is user is taking and then you have to decide okay in this particular operation i will run that business rule so maybe if user is inserting the data that means insert updating the data update deleting the data delete or querying these are the four operations which user will take and then you will decide okay this kind of condition should met and run the business rule so if you want to display a message every time user insert an incident in that case you will just select the insert and you will populate the message so it will run every time on incident table now practically i will show you some examples but these are the operations and i will show you each and every example for or when and what operation both how exactly they work basically i will show you by changing all the different fields we have in business rule and their functionality practically in service now global variables of business rule now servicenow provides some declared global variables and those are current previous g underscore scratch pad and gs that is glide system now current is something which stores the current racket fields and values that's what it stores previous if you are changing the data if you are updating the data and you want to fetch the old values that it will be saved in previous and then we have g underscore scratchpad if you remember we already talked about this in display business rule so if you want to fetch some uh value or field value from database from server end on a client in that case you can use g underscore scratch pad and then you have gs now gs has a lot of methods which you can utilize that i will show you in my practical session this video is about create br with scripting and without scripting so we will not just create one br i will show you by creating different business rules as per your requirement so that you can think of in the future if you will get the different requirements different uh like um customization needed which is uh required from your clients then you can think of that yes i need to create this kind of business rule as for the examples you will see um in my video so let's start by creating business tools with scripting and without scripting before i start creating business rules let me quickly show you the baseline the out of the box business rules in order to see out of the box business rules you can go to business rules and you can type here under system definition application menu you can click on business rules once i will click on business tools it will show me the list of business tools i have in my service now system now these business rules are there as per the functionalities you have enabled in your system now here it says like 2373 that means out of the box servicenow has created 2373 i have not created even a single business rule as of now in this particular instance now this number which you can see on the screen these are all baseline business rules that means which are from directly from servicenow so to enable the functionality to provide some functionality servicenow has already created business tools on those tables now this number can increase can decrease as per your system because this depends on the plug-in this depends on the functionality you have enabled in your system or maybe if you have already your system and you have maybe created some business rules in the past then it might change the number so do not go with these numbers it's just the number as for the functionality enabled in the system the system which you are logged in so let's create a basic business rule to show you the example now in this in as i told you in this session i will create uh multiple business tools with multiple functionalities of business rules that how exactly you can select different options like how can you select when are different operations conditions then scripting that's what we are going to select we also learned about global variables and i will show you how exactly you can utilize those global variables like current previous then underscore scratch pad and gs as well so let's start creating business rule so we will start with the basic business rule and that would be so i will go to incident table now if you remember uh this this button i showed you if i click this button it will open up the business rule form it will show you the business rule form and then you can select the table and then you can create the business tool but if you want to directly select the table on which you want to create it then in that case you can go to the list of that particular table because now you have admin access you can right click on the on the menu item this context menu then you will go to configure and then go to business rules if i click business rules it will show me this list now and this is showing me all the business rules created for incident table now if you remember we also have task table and all these tables like incident change problem they are all inherited and extended from task table so it might happen that some of the business rules are running directly on the parent table not on a child table it is as per the requirement you have it's not mandatory that you have to write the business rule every time on the parent table it depends on the requirement you have from your customers and you from from your clients so let's start creating a new business tool so i'm just clicking this button new when i will click this button you will see one thing which we didn't see in in the system definition business rules that table is automatically selected which you don't see in in system definition because that shows you uh business rules for all the uh tables here because you came with uh that option like configure the business rules on that particular table and that's the reason it automatically selected uh table so it's showing incident now i will do one thing i will do auto populate description if if empty so what we exactly we want if description is empty and description is not mandatory on incident form so if you just want to copy similarly what we have in short description so auto populate description is empty with sd if empty let's copy short description now it's not taking more uh characters right now so i will do when to run first in one to run i will do it in insert just a basic we are doing we are not going to do any scripting i'm making it an insert filter condition so condition is description is empty yes that's what we want description is empty then only we want to do that so if it's empty i will go to action i will do description so description is same as it will be same as short description now these are every time when you create business rules always see as per your requirement and see what will be the best operator for you whether it's two whether it should be same as what that's what you need to select and this is not something i can tell you in one video it's up to your decision as per your requirement you have to think what can give you the best result so as of now if i will make it two that means i want to populate something with by giving some value myself but by as per the requirement we mentioned i want to copy the short description directly in description if it is empty so that's the reason i will select same as and i will select short description i don't need anything else as a set of values and i don't need to select advanced because i'm not doing anything and if you want to check whether it's it is doing before insert after insert that you can select but as of now i am not selecting it just to show you and i am going to save this once i have saved this i will create a new incident i have opened up the form so this is the incident form i am selecting the caller and i am test data to copy to description i am just inserting the incision right now save done so as you can see incident is created and i have similar data which i have in short description so it automatically copied it i don't have to type anything now let's let's see if i'm not if if description it has something so i go to create new again and i am opening the incident so i have this form and i put test data now this time this is my this now this time it should not run it should not run that business rule because the condition we have mentioned to run that business rule is the description is empty so if i save this let's save this yep now it did not work because that business tool is not triggered whatever action user is taking it is doing as it is that's a difference so this is how you create a basic business rule let's take some another example and try to configure some more options we will still continue to do it without scripting we will do some scripting later so i'm back to my business tool i'm deactivating it right now let's try to create a new business tool in this case i will select the advanced button as well and i will select this now here you have insert update delete query as of now you understood about uh like just insert we just inserted let's try to check something about update so i am unchecking this and i am checking update now here you have to select whether it's before update whether it's after update or it's just async or on display so let's do before update what exactly i want to do so in that case i will select so i will do one thing i will select if description is empty let's let's continue with this if description is empty but i want something i know uh description is not mandatory but if i put just empty for now just to trigger this so before update it checks if description is empty now what exactly we want we will abort the action this time so we will abort the action we will add a message and we will tell hey you need to fill this encryption as well now i'm sure you don't want this update before insert right or before update because this is something you are aborting the action you don't want user to create that ticket so if i update and it sees this particular option description is empty action would take hey you need to full description as well and i'm aborting the action so i'm inserting and stay i have already kept the previous business rule act uh it's inactive but it's still uh still like there in the system so i'm not i'm not uh deleting that i'm just creating a new so i have done insert and stay name is still same but this time i can change it if you want i will do it about if description is empty i'm just saving this so this is save now i will update the record so this is just a previous record so if i am putting the this and i have put in the short description now i have inserted the racket because it's not checking anything because on insert we have deactivated that business rule so that's the reason it is not copying anything but if i will update something it will definitely alert me and abort my action so let's try to update maybe contact type i'm making it as email when i'm making it as an email i'm going to save this if i will save this you can see it says invalid update hey you need to fill description as well it copied it it copied the description basically because action was already there so if i reload the form i still have this as none because it has not saved the data so if i go to back to my business rule and i have this in action that was already there but i think i we don't have anything in the action it is still showing because we are aborting aborting the but let me let me do one thing yes that's the reason it is still there so what i will do i will cancel this now i will add the message i will abort it i will save this now you will see some difference this incident is already there i'm again making as in progress now this will abort it again it will not update the state i am saving it it will give me the alert invalid update hey you need to fill the description as well that's what it is doing now why is it is taking me uh to the uh that business rule form because it just went over there i have to go to again i will open up any incident i will go here it's just like it did update and just went back to the previous form so i have this incident i will make it in progress and try to update let it load first yeah i am going to save this and it's saying me invalid update and showing me the message this time it is not copying anything because we insert we did in certain stay but even we never removed that action now we have removed that because it was saved in another business so the second business rule we created so this time it is not copied and it's not enabled so and i don't have anything here even this you can see it is only on the client if i will reload this form you will see it is back to the new because that was invalid update so it aborted it stopped that action so whatever user is taking any action it aborted it let's let's try to deactivate this business rule again so i'm deactivating it let's try to set some field values like choice field values so before that i will see the functionality so if i go here out of the box if i select this i put something here this is new and if i select any assignment group and i save it you can see it is still in a like new state it's still new now if you want to put it in in progress for example if assigned to is there that means if assigned to has some value this state should automatically be changed to in progress how can you do that so the requirement is your client comes to you that hey whenever i see assign to whenever assign two is converted from empty to something then state should become in progress so in that case you have to write a business rule so i will go here i will create a business rule so we will write the business rule as set state 2 in progress and when exactly we need to run it we have to run it on update or maybe insert as well because you might change the assignee as well so in that case you have to put so the condition for this is assignment group is not empty because that's really needed right so assignment group is not empty and at the same time assignee assigned to i think changes to will not be good so we can do assign to is also not empty so if assignment group is not empty and assigned to is not empty what it should do it should automatically update the state to in progress but one another condition is also needed that is assigned to changes this is really important because the condition is assigned to is not empty assigned to is also not empty and assigned to changes that is what you have to do so i am going to action i am selecting state because i have to set the value of state and this would be in progress now in incident if you remember my incident management training i mentioned that in state we don't only we not only have the state we also have instant state so you have to do both you have to set both the values to in progress so i am or maybe if you want to add a message state got changed and when exactly you want this before insert or but i think it's up to you but let's do before and we're not doing anything in coding i'm just saving this and this time i'm going to create a new incident so i'm creating the new incident it just and i'm putting an assignment group i am saving this so as of now it won't run because assigned to is still empty and we have put in assigned to is not empty so it is still checking that condition has not met now if i put something if i put this person and now i save this once i save this you can see i got the message which i mentioned state got changed and i also see here that state is in progress and if you will reload so this is not something just on client that's what you have to remember of a business rule that if you remember when we wrote something some scripting on client scripts when you push some value so there was a api which was like a g underscore form dot set value that pushes the data only on the client that means on the browser on the form it does not save it until user clicks that button to save it but here there's a big difference when you are setting a value in business rule then you do not have to wait for uh like saving user doesn't have to save it again if you will set the value it will automatically change the state and also save it in the database directly that's the difference between client script and business rules let's take an example of another operation that is delete so i will uncheck this and if you remember uh we we checked insert and update both that means it was working on both even if i insert the data even if i update the data now delete now this operation is something if i am deleting a record so as of now we were inserting we were updating and what if i am deleting a record what exactly you want to do in that case let's let's do one thing that if i have a uh uh let me give you the uh requirement that your customer comes in and say to you that if any user tries to idle you won't give users to delete the incident but i'm just giving you an example that if customer says you that if any user is trying to delete uh delete the incident it should check whether it has any parent uh like parent record and then if it has then it should not delete it that's what you have so i will do one thing i will go to list i will go to business rules and the one thing i will do i will make it disabled and now i'm going to create a new business rule and we will abort it basically now abort deletion if parent is not empty so the condition is if you remember we have a parent incident so if i go to incident i open this we have a related record yeah that says parent incident so i go back to my business rule i will select parent incident so if parent incident is not empty and i'm doing it on before delete so if parent incidence is not empty then i want to abort this action because i don't want user to delete it so i am saving this this is saved and this is before delete because you don't want this action to be taken after delete right you have to do it before delete you want to abort that action so it's something if you you definitely might create some of the business rules after delete but it depends on the requirement maybe after delete you want to send a notification to all the users or something like that whatever it depends it depends on the requirement but mostly in this case we want to abort the action so we can't put it after uh delete we have to do it before delete before that this operation so if this is before and it's before delete now i will go to my incident and this is saved i will go to my incident i will try to put a parent incident here and this will be so i'm going to put this one here i think i can't keep the same one it has opened the same incident i will open another one i will open 2 9 and now i will put the parent i will save it so parent is saved parent incident says invalid update if i yep it's not giving an invalid update so now this incident is a child incident and it has this parent incident now i'm going to delete this incident even i am admin even i am admin i'm i can delete it because that's what i have access people can also delete other record it depends the kind of role you have given but idly if i talk about the organization's perspective you should not allow people you should not allow users to delete the records either you archive them that's what you can do or you you close them or you don't show them that's what you can do i think the best way to do this is archiving yes i think even in archiving you can delete records but you should not delete your recent records it can be maybe two years ago the data which was created two two years ago that you can delete so just to give you a suggestion so here i'm going to delete it once i'm clicking on delete it says i have one task sla this is out of the box this is not something i have created with the business rule this is out of the box because whenever you delete a record service now always checks some other things what things are there so it is just telling me that if you will delete this record it will also delete one task sla which is referencing this record so i am deleting this if i click on delete it it was not deleted you can see the 2 9 is still there because action was aborted i'm not able to delete this i will try again in front of you if i click delete it aborted my action and i am not able to delete it now let me deactivate that business rule so i am deactivating this business so and now i am saving this now i'm going to delete that record so i have deactivated it it would it won't abort that action anymore so i'm clicking on delete it is saying me this warning i see yes proceed if i click it it is taking me to the list okay it's take me to the previous business rule i'm opening the list i have the list now you can see that two nine incident is not in our system it has been deleted now this might happen that sometimes you delete it by mistake in that case we have a module called delete records and if i click here you will definitely see my latest incident so it says record deleted yep this was the one so this was the one which we deleted it is showing me if you want to recover this you can also do that it says recover entire operation and if i click here it has been recovered and if i go to my incident list so it's it's not there okay let me go back it says ready to recover i have to click on roll back that's what i so it says roll back entirely show you want to recover yes okay it didn't do because i did not select yes i have to select yes and i now i'm clicking on ok now it's recovering so it's done if i go to my incident yep i have my incident back so i deleted it but now i have my incident back with all the information which it had so this is how you can create the business rule on delete operation as well let's try to uh put a business rule on query and then you will be able to understand all these four operations that what kind of requirement you will get and then what exactly you need to select whether incident delete update or query query business rule query business rule is another kind of business rule it's another operation where user actions which basically whenever user hits any uh table like a via module it always does like a query because it is fetching the data it's similar like uh you are fetching the data from a database like select start from table like you're acquiring it that's what it is doing so it is pulling the data from the database and that's what you can see on the screen so let's if i go to the incident table i have these records and if i impersonate itel user i go to idle user and i go to all so if i select all as of now i can see 92 incidents so every time i click on all or maybe i i click open as well it will show me all 92 incidents it is putting up the filter as per the module but basically it is querying the whole data i want to restrict that one of the requirement which i can tell you that your customer comes to you and says that hey i don't want users to hit my incident table for the records which are more than one year i don't want them to hit that query even if they are closed even they are open whatever state regardless of that idly people will not ask you but i i really want you guys to understand how these functionalities work so i'm just giving you the random example not the real real life example it can be it depends on your customer requirement but it might happen they add some more conditions that you have to decide that's the reason i'm just giving a random requirement that that if your customer says that it'll users should not be able to hit the incident table for the records which are older than one area so if i go here and i go to open or maybe let's go to all as an admin view i have 92 records and i go here and i see the records which were created not on or on last year or not on last year anyone you can select which will give you some data last year not on last year as of now i have 92 if i run this i have 68. so i just want users to see this data not whole data they should not be able to query whole data in that case now this this example this querying is an example uh i think if i if i give example of users table another scenario where you don't want your idle users to see inactive users just active users as an admin you can see any racket you want but for idle users or some other users you don't want them to see inactive users in that case you can utilize this functionality as well and this functionality is out of the box but the one which i am showing you right now it is not out of the box i am going to create it in front of you so as of not showing me 68 what i will do i will just copy this query because we will use some scripting in it i will go to configure business rules i will create a business rule and i will put here limit the incident query for non admins so admin can still see and i will show you practically so incident table is selected i'm not doing anything here at least in filter conditions but i will have to do one thing i will select this query and i will do before query now i will go to advanced i don't have to do anything in actions right now i will go to advanced first i will put the condition and what condition we just thought of that is admin user should be able to do the query for all the incidents even they are from whatever time so in that case i will put some bracket i will put gs so if you remember we talked about this global variable global object we have that is gs i put gs dot has role this is one of the method we have has role and i put admin as of now it says that the condition is the user the logged in user should have admin role but i will make it not by putting not here exclamation here now it becomes not so if user logged in user is not admin then do this what do this it have to be mentioned in scripting here i will do current dot now it's it shows you the current records active records you have it the the one we are working on right now here i will do add encoded query and i will just paste the query i copied i will put the semicolon and i will save this once i will save this now i will show you in both the views one is my admin so i'm going to all and i can still see 92 incidents because i am an admin but if i impersonate itel user and i go to the same module which admin was clicking so initially you must have seen even your admin even your non-admin or ital you could see 92 records but now admin can see 92 records but let's see how many records itel user can see so if i click all i just see 68 records and they were the same count if you remember that all the incidents which are not created last year this is how you can limit the query this will not just work on your list this will also work on your reporting as well yes if you will do reporting then it will also work over there so user will only be able to query from this table for these records rest not so this is the example of query business rule so the topic we are going to talk about is business rules with advanced scripting so in this particular session you are just going to learn about different kind of scripting you can do as per the different scenario you have i have just selected few scenarios practical scenarios it might not happen that you might get a similar kind of scenarios but just to make you understand that how exactly and when exactly you will think that yes i have to write this kind of business rule or i have to write or have to utilize this kind of logic to fulfill this particular requirement and in order to do that i have just selected the just kind of a diversified kind of uh situations and scenarios so that you can understand better so i have not just selected incident table i have selected group table user table i have selected uh some some task table as well so let's start with the first scenario and let's do the scripting with business rules the first scenario we have is create five standard tasks when you create a story so the requirement is if a user creates a story now automatically five some tasks should be created for that particular story so let's take a look at how exactly we can fulfill this requirement so this is my personal developer instance i will go to first agile application where we have stories so we have this all stories this is my story so the requirement is whenever i create a story it should automatically create five scrum tasks now this was created manually now what if you want to create automatically and it also should select this type and it should also add the short description so in that case if i double click here the kind of task i have is analysis coding documentation testing that is what i have and what i will do i will open this and check the different type i have so if i go to choices i have one two three four so that is analysis coding documentation and testing so let's go to stories now in order to fulfill this functionality i will create a business rule and that is also with scripting so i will right click here everything is always left click like if you will right click it will again show the same options but i always say right click but i always click left click so but yeah if you will do left click here it will show these options now you can go to business rules and then click on create new so we have table already selected i will do create scrum tasks in i will click on advanced and i will do it on insert and i will do after insert i don't have to put any condition i will go to advanced now because i need to write scripting so i will go to story because now i need to check the table of the scrum task so i will go to story i will go at the bottom and see the table we have for this scrum task so the name of the table is this one now in order to create record in service now with the help of scripting you always need to use glide record and you have to initiate that record in that case you can create a record in service now with the help of scripting let's take a look how exactly you can do that so i will start with ver gr equal to new glide record i am putting the table name here now i will initialize this that's i'm initializing then i'm putting gr now i will set the values so if i start with gr dot i think we had type so if i put equal to one if i put g r dot short underscore description equal to analysis and then i do gr dot parent is equal to current dot says id gr dot and then i will do insert if you are done with setting up the values then you can just use the insert method so now i am done so if you remember the requirement was we need to create five tasks but as of now i'm just creating one with this analysis so let's take a look whether it is creating or not so if i am saving this and if i go to my story list click on new and create a test for task if i save it and if i go at the bottom now you can see that i did not do anything it it automatically created the scrum task with the same type which we mentioned now how would you create all these tasks like four times let's let's do it four times with all the types we have how exactly you will do that so as of now it is just creating once but now i will go back to my code and the same business rule now i have to iterate it so iteration means i have to repeat it i need to do a loop so that it should check that it should create four records for me as one two three so in that case what i will do i will do 4 i will use just for loop so i will do i equal to 0 or maybe i will start with i equal to 1 and then i will put i less than 5 and then i have i plus plus and then so this is something i'm i have loop now in that case what i will do i will also do one thing i will now it says gi dot type one because it will select that analysis type but we have to do it for every type one two three four for that i can do one thing i can write here maybe where type equal to i that's what i can i can put now every time it should do i plus plus so type is equal to i dot to a string now here i can put type so it will it will automatically select the i value it will convert into two string and put it here let's see if if it does that but at the same time we will have this short description but we can do one thing we will not use this so maybe we will do scrum task plus type that is what i have i have this gi dot type this type and i am saving this if i am saving this i'm going to back to my story that means i will go to the list again i will create a new story test for four tasks i'm inserting it now it will run the loop so did you see that we got four scrum tasks it also mentions come task one screen task two scum task three scrum task four and also selected the right types so this is how you can utilize and fulfill the requirement now requirement can be different as for your customer requirement it's not something but you can understand the logic that how exactly or in what condition you will use business rules with scripting the second scenario we have is close request item if catalog task is closed so if you have a request item and it has one or more catalog tasks under that request item once they are closed then you can close complete the request item this is the requirement from your client or customer and this is our another scenario so if i go to my personal developer instance and i search for service catalog under catalog i have these open records so if i go to items i have this one as of now it's open and if i go here it's already closed complete so you can see it it got closed complete but this is still open so the requirement is whenever all the tasks are closed it should automatically close the request item as well that means the parent one now the next point is where exactly you will write the business rule now you will definitely achieve this requirement with business rule but where exactly you will write it that's important question for that you have to write that business rule on this catalog task and the reason behind it because the important point in business rule is trigger now you are not touching request item ideally because you are updating the catalog task you you're updating the state of the catalog task which will lead to close the request item so what i will do i will write a business rule on catalog task so if i will go here i will go to business rules click on new set state to closed for ritm i will check on advanced and i will do it after insert or no we will do on after update because i'm not inserting anything right now i'm just changing the state of the task so when exactly i would run it now i want to run this and i want to do a check whenever i'm updating the catalog task at the same time i am also checking the condition whether state is getting changed so i do like state changes to closed complete this is the trigger point we have like when to run how to run that's what we will do here what action it should take that will be mentioned in our scripting so whenever i update the record that means the catalog task record it should check that do i still have any open task if not then only it should set the request item value to close complete so what i will do i will do a glide record where gr equal to new glide record and the table i will select is the catalog task because i need to check for the open items right now so i will do gr dot add active query i will look for all active records so ideally i think if i will if i will do a close complete to catalog task it should become deactivated but that we can see if if we have that option so in that case i will go to [Music] tasks it says active is called to true and if i click on so yeah that's true so i have this closed complete so the best option here for your scripting is add active query i do it but i still have to mention one another condition that if if this this particular field request underscore item now i need to check whether i have active or not so i will do one thing i will check it whether gr.add query and i will check the request item now i will do the parent basically the parent i have add request item add query i have to check if i have any open for that particular request so i will do the gi dot add query request item that is current dot request item if it's similar then i have gr dot add just query this time and then if because i don't need to use while because i just need to find one record if it has that's what i need to find so i will do gr dot next so if i i get any record but what i want i want to close complete so the main point is if i don't get any record so if i do not have any active record and it already got close complete in that case what i will do i will do another glide record where gr i equal to new glide record sc req item this is the table name for request item gri dot add query that we have society is current dot request item gri dot query gri dot next and that will do gri dot state equal to and if i remember it is three the close complete is three so and i will do gri dot update that is what i will do so i am clicking on save and i'm just it's saved right now and now let's try to close the task now before that i need to submit a request that's what i need to do so what i will do i will go to request item i will just create a random request item and i will save this let's create catalog task under this so it is test one submit then i have another one test test 2 submit so i have these two let's try to pull state field that's what we need to see whether it is working or not i have state field so this is my request item and i have these two catalog task let's try to close the first one if i close it close complete is it doing anything no let's refresh it and the reason behind it i still have another task let's try to close this one if i close it as per our business rule it should automatically close this request item so i go here close it and if i see now you can see it just changed the value and it got changed to close complete and you don't have to even save the record you can just reload the form yes you don't have to click the save button it automatically updated that record directly in the database the both the tasks are completed and my request item is also completed but this is how you can write another business rule with a scripting for a different functionality this is our third scenario so the scenario is if assignee updates the incident then change the state to work in progress and i would say i think you might get this kind of requirement in your organization as well or maybe from your customer or clients so let's take a look that how exactly you can fulfill this requirement so if i go to the incident form so the requirement is as of now you can see it's in the state is new and the requirement is if i change the work notes and i save this the ticket should automatically change to in progress but the only condition is if the logged in user is the assigned to person so in that case we have to write the business rule so let's do that so i am going to business rules create new set state to in progress and when exactly we want to run this we want to run on update and update and that is also when work notes gets changed so whenever work notes gets changed that's the reason we have to check this particular condition and that's how it will trigger so if i go here in advanced now i have to change the state to in progress if the current logged in user is in assigning so in that case i will get the assignee and i can get it with the help of current so what i will do where c user that is current user so that will be current dot this will be assigned to basically a sign or maybe a sign and then i will put where c user that is current user it's a logged in user basically so i have a gs dot get user id i put dot semicolon here i do if assign equal to equal to c user that means if they are same if the assignee is similar to the logged in user in that case and work work work nodes gets changed then i will set the current dot state equal to i have in progress and if i check what is the value of in progress so i need to go to configure dictionary so i have in progress mostly it's two so you'll go for two so i will put two here and just and then i will save this so now i'm saving this now i will do one thing i will impersonate to itel user so i will create a new ticket saving this so incident is created i will put my id itel and then i will use the grip it's application development so let's see if i have that i till so maybe we can check what what exactly my groups are so in that case let's impersonate the p person who are in these groups like application development so we have this person andrei arch i will copy this user now i will impersonate him because i was not able to find the right group for idle user so i will do with this particular user i'm going to open if i have any it's not assigned to me but now i can select application development and then i can put my name um just updating it now as of now you can see it's it's new earlier it was in progress so it says was new like in progress and now if i put my this grip it automatically change to in progress if i put something now you can see it got changed to in progress so if i go to another instant it's new i will put my name put the assignment group save it now this thing which we are seeing like it is automatically changing to in progress whenever i am putting the assign to now that's it that is something different that if you are putting some assigned to and it is making it in progress but i am just telling you and it is not running because of our business rule i will make it new again and this is running because of another business rule because our condition is totally different now as of now you can see we have this new now i am putting a work node test and i click post it automatically changing the state to end progress because the logged in user is the same one now what if if i remove this and now i save this and then i go to work notes and just per test again and post it now you can see it doesn't change anything i have posted the work node but it does not change anything so this is how you can fulfill this particular requirement with the help of scripting so as you if you remember i i showed you three scenarios where you can write and you can utilize scripting and business rules with different situations now there are number of i think n number of situations or different requirements you can get from your customers which will i think you will decide that how exactly you have to write where exactly you have to write what trigger you have to mention what table you have to select that's what you have to decide when you get the exact requirement from your customers in this session we are going to talk about business rule with scratch pad in one of my session we learned about that what is business rule and what are the global objects of business rule now one of the global objective business rule is g underscore scratch pad so this is what we are going to use in this particular session so i will show you the practical example then what use case you can utilize g underscore scratch pad and what kind of requirement you will get from the customer or client and then you will think okay i should have to create g underscore scratchpad business rule so let's take a look how exactly you can do that in your instance so i will go to my personal developer instance in order to do that let me tell you basic use case now the basic use case is if i go to incident and i open any incident so what i want whenever i open any incident it should show me an alert and on that alert i should be able to see caller's location that is what i want now as you can see the caller's location is not on the form so we cannot show it as per the client because alert is always runs on client on the user's browser so i have to fetch that value from the database which is which will pull that value from caller uh basically this user table and then it will display it but i cannot utilize client script because i cannot fix that value basically there are some other ways if you remember in client screen we talked about get reference so you can still do that but g underscore scratch pad is it's also one of the i would say best example it will it will do kind of a async job that's what it will do it will just get the value from the database and then it will show you on the screen so whenever if you get any kind of requirement where you have to fetch some two three fields from uh from server and which is not on the client and you have to populate that value on the client then g underscore scratch pad is the best way to do that because showing the value of like server fields or server data on the client there are various ways like we have glide ajax we have g underscore scratch pad another one we have get reference all three methods they are the best practices basically so but but if i i would say all right overall recommendation is clyde ajax but g underscore scratch pad is also recommendable and you can use it you can also use get reference but i would say let's ignore that get reference but you can always use uh g underscore scratch pad and glide ajax those are the best recommendable approach for fetching the values for the client so what i would do i would write a business rule so i would go to business rules and let me tell you one thing before that we definitely have these scratch pads out of the box as well and if i will search it here you will see one is written on task table and one is written on incident table it says load incident models into scratchpad if i click this i will be able to see what all values i have saved so you can see we have uh we have this incident state and we have this incident reason that's what we have done so it's up to you you want to edit this is out of the box so i'm not going to touch this i just wanted to show you but i will create a new business rule now for g underscore scratchpad if you remember we talked about display business rule now that is what you have to select here in when you will not select before after or async you have to select display business rule in order to use g underscore scratch pad now this is the condition and if i so i will run this on display there's no condition as of now it would show you every time so it will get that value every time i want here what i will do so as you know in business rule you can always get the current records so current fields you can fetch those values you have you can store those values and that's what you have current in that case what you can do you can do so in order to declare this scratch pad you always go for g underscore scratch pad dot now you have to give the value to it so let's take an example of c location that is what i am putting and if i go equal to here i will put current dot so i will put caller id dot and i have location so if i go to sys user table dot list i open this record do i have location here i have department i don't have location so in that case let's let's pull department so i have this department i go here and i put it department now when this value this this business rule will run it will pull the value of caller id department here and it will save in scratch pad and the the variable which we have created that is dc location that's what we have used so what i'm going to do i'm just putting sas scratch pad saving this i will go to incident i will go to client script because i need to populate that alert so i will go to client script i will create a new alert for department i will type here on load so i want whenever like form gets loaded it showed that department like it's not something that you will get the same kind of scenario your customer might give you different scenario i'm just showing you the example that how exactly you can utilize gnscore scratchpad here what i will do first i will save the value of the location department basically so c i think our we could do department it's a variable we are declaring and i will put g underscore scratch pad dot c location so it's a variable name so it won't matter but anyhow we are getting the department so i have where department and here i will do alert the callers department is department i have written here and it would run every time we load the form so i am saving this now we will see whether we are getting right data or not id i would think this would give you the cis id let's take a look what exactly it gives if i go to open i open any form so now you can see i was correct so it says the callers department is this so you can see it's giving the society of that the reason behind it because department field is a reference field and that's reason it is giving you the society now how can we get how can we get the string the name of that particular department for that what i can do i can go back to my business rule here i will do one thing get display value that's what i can do and if i save here i go back to my incident and i reload it this time you can say you can see that caller's department is customer support so that's a big difference now whenever you perform development development in your instance or you perform development in your organization this these are the small things we need which you need to take care that what kind of fields data you are fetching that's what you have to always remember whether you're getting the right data or not so anyhow you'll be doing the development and then you'll perform the unit testing but make sure you are testing each and everything before delivering it to the client and customers so this is the example of g underscore scratch pad and how exactly you can use g underscore scratch pad in this particular session we are going to talk about glide system now this is one of the important api when you write business rules or do any kind of server scripting and if you remember we already talked about in our previous session about client-side scripting and server-side scripting and we also talked about their different kind of apis we have from servers now so glide system is one of the api which is really important so i will show you that how exactly you can utilize this glide system we will show you some examples around business tools because as of now you have learnt business rules and if you remember when i when i mentioned about my scripting related to business tools in the same session i also used glide system and at the same time i also used glide record glide record will be my next session so in this session we will just talk about glide system what exactly it is that and how exactly you can use it what are we going to learn in this session we are going to talk about what is glide system glide system methods example of glide system what is glide system now glyph system is an object to access system level information it provides number of methods so it comes with the methods which you can utilize to calc to access the system level information it provides methods to perform dates calculation and the most important part is it runs on server side so as i mentioned earlier that you have some kind of apis which will run on client some apis which run on server so this is one of the api we have that is light system glide system methods now these are some methods but it's not something that these are only methods we have in under glide system we have multiple methods which i will show you in my examples when i will try to create some business rules here you can see some basic example of glide system methods like we have get user get username get user display name get user id and then has role but we have more and lot of glide system methods so let's take a look in our personal developer instance that how many apis we have and let's create some business tools with the help of glide system that what all thing you can do with the help of glide system now this is my personal developer instance i will go to business rules under system definition i will just deactivate my previous business rules so i will create a new business rule so this is my business rule form i will click on advanced because now we are talking about glass system that is scripting so we have to enable scripting and this is something i can do before or maybe after maybe on update and then i will go to advanced but i can also give the name here so gs demo that's what i have given let's take incident table you can take any table you want but i'm just taking incident table so now what exactly i i can do to get this gs methods for that i have to type gs and if i type gs and i just press dot these are the methods for glide system and that's how you declare so the syntax of glide system object is gs dot you will get all the methods for glide system and you can see we have lot of methods for glide system so if i start with let's let's take an example so example i can take here um let's see if i will i will populate something uh on on the form like a message at the on the top of the form and i will populate a user's information user information means the logged in user and how exactly i will do so i will do if or maybe every time every time user logs in so i will do gs dot add info message and here i can type or you can know get user now why i'm typing this because i will get the method what exactly it returns so that you will be able to know what exactly you have to use when you really fulfill the requirement of your customer so here i can do one thing gs dot i will do get user so i have this get user i will press tab it will automatically populate the braces now here the next one i will do gs dot add info message here i can put get user id and i can put g g s dot get user id so we will see what exactly result it gives and then we will do gs dot add info message so i have get user display and i have gs dot get user display name again semicolon and then i can do gs dot add info method get username plus this is why what we have so as you can see for user we have all these methods to get the you current logged in user's information and where exactly it will populate it will show an info message on the top of the form and it's showing on update that's what it will do and it will run on every condition basically so whenever you will update any field it will just show these information so what i will do i will just save this for now so we will keep on using this particular business rule just to show you all the examples and i will do one more thing i can show in you in bigger screens a little bit zoom basically so i will zoom in so that you can see what exactly i'm doing so this is the script we have written now we will try to run the code so we will go to incident this is my incident and now i'm just updating random information that was the client script which i wrote just to show you a different demo so i will save this so it should show those messages on update and now you can see i have updated now these are the information so you can see it gives me all these information get user it give me this information then i have society and then i have display administ that is my system administrator and then i have admin now this is the name in order to know all these things what you can do i will put some space here and i'm saving this again and now i am reloading it or just saving it again so now i saved it now you can see i have space so the first method that means get user is giving you this com glide.user at this that is what it is giving so and then you have this one society so get user id gives you the society of the current logged in user get user display name gives you the name complete name of the user and then get username gives you the first name basically and that is the username there's a field not just first name the field that's called the user name that where you typed login as well that's what it is showing you so if i go here and you can check these things as well for example if i go here i just put dot and i put get user it says returns a reference to the glide user object for the current user that means it is returning a reference the very exactly this this user is mentioned that's what it is mentioning then we have display name it says get the display name of the current user that's what it is showing you now this is the user id society and this is the username that is the user id of the current logged in user now this would apply in every situation wherever we have wherever we will just update the form that is incident form and it will it will show you this information so this was one of the example of gs with get user but we have more methods as well and we can see so if i go here this is the profile i had and if i select default view so you can see my user id is admin these are my first name last name so i got the complete name as well this is the complete name don't don't see that this is the title that's not my first complete name that's just a title but what exactly it gives so we do have a field as well where it clubs first name and last name in service now so i go back to my business rule and i will make it full screen and just increase the size little bit i'm just minimizing this navigator just to show you more information about gs so if i type gs dot you can see we have a lot of other methods like add error message add info 64 now these are some time and date methods which will help you to calculate these information but as you can see there's a long list end of this quarter error then we have event queue as well these are all different methods which you can use with glide system we will just utilize these get user then you have also has role whether you want to check so these are all information if you want to get information about all the apis methods you have of glide system then you can also find on servicenow website that is developer.servicenow.com and there's a section called api list and you just click on that click on server and then you will find this glide system api with their all the methods in in glide system that is what you can get it from there in this session we are going to talk about glide record in our previous sessions we learned about client side scripting server side scripting business tools client scripts ui policy and we also learned about glide system which you can write on server side now another api we have is glide record glide record it's really important i would say uh object in service now and the reason behind it because most of the developers when they do coding in servicenow they definitely utilize this api so let's start with what exactly we are going to learn in this session so what is glide racket glide record methods and then example of glide record so i will show you some practical examples of glide record and all the methods practically in service now just like a small lab what is glide racket so glide records is an object containing records it is used for database operations and the important part is it is executed on server side so if you remember that you can run the code on client side you can run the code on server side but if i talk about glide record it should be executed on server side now what is the use of light racket glide record is something similar like sql command so as you play with database with sql when you uh do some kind of fetch some records or update some records delete some records in that case because that you do directly on the database but as servicenow is a cloud uh platform so you cannot access directly their databases not even any server because it's just a front-end application that's on cloud and you can just do whatever development with the help of whatever apis they have provided that is what you can do with servicenow now but you still need to play with records you still need to play with tables and you have to do some database operations like insert delete update or fetch some data like query now how exactly you do that in that case you utilize glide record one of the important point of glide record is that it can also be executed on client side but it is avoided due to performance impact there are some methods on client script which which basically does the similar kind of work like we have glide record so they go into database and fetch the details for you for example g underscore form dot get reference if you remember i mentioned this method in my client script session but in this session we will just talk about server side code that how exactly you can utilize glide racket and what kind of different methods you have or what kind of different database operations you can do with the help of glide racket this is my personal developer instance now the important point about glide record is syntax of glide racket so what i will do i will go to business rule so under system definition i have business rule i will create a new business rule demo for glide record and you can select any table you want let's select incident table now i will just show you the example that how exactly you can use glide record i'm not going to show you the example uh for the exact use case because i will just write i'm just utilizing business rule to just run the code i can run this code in another functionality as well like we have background script and we have fix a script but i do not want to confuse my viewers and then the people who are watching my video so just to make it simple i'm just running the code in business tool so that i can show you how exactly you can utilize glide record so i will just enable this advanced because we are going to use glide racket so scripting has to be enabled and i will do after update so we will just take one record one incident and we will keep on updating it and we will see what results we are getting so in that case i will go to advanced so let's start with the syntax of glide racket now how exactly you do that now for creating a glide record you have to create a glide record object for that particular table so in this case what we will do we will try to populate number of incidents maybe let's let's do what exactly we can do so let's start with creating a variable and you can start with where gr new glide record so everything is case sensitive so whatever we are writing you have to remember the exact syntax so we have variable gr now you can definitely change the name of the variables and you can also change the table name so when you create a glide record object you created create a variable and then you put the table name here after glide record so what i will do i will put incident now i am just hitting the incident table as of now now i want to query it but before acquiring it i want to put some conditions that what kind of data i need so in that case what you can do gr dot so when you will type gr dot it will give you the methods which you can utilize and the common method which we have for glide record is add query so this is the common method we have for glide record so here i can put some conditions let's take an example that state comma means state equal to maybe let's take one and then i have gr dot now i have put in the condition now i will execute this query basically and how exactly i will do that so it will check the condition and then it will do a query and i will tell you what things will not change for your glide record what will be static or what has to be there every time so in that case we have this where gr equal to glide record then we have add query and they have this is like giving the query so it's gr dot query now i will process the records so what exactly i want to do do i want to pin print these records what exactly i want to do so in that case what you will do you will do if now here is the important thing as of now you can see i am typing if but if if you will type just if then it will show you only one racket but here if i will type while the general syntax of glide record is with while but if you just want to fetch just one record and that would be the random racket but with the condition mentioned here so in that case what i will do i will go for next record so i will not do while because it will fetch all the records whose states are one so i'm not doing that right now so i will do if gr dot next if it's next that means if i get any record whose state is one at least one record what should i do so i will do gs dot add info message and here i can put the message like the incident number and here what i can do i will do plus gr dot now once you have queried you have touched the database now whatever record you are it is giving you back that you can get the details of that particular record you can print that so here i can do gr dot number and i'm going to save this so first i will minimize this i will go when to run it's on after update and like whenever i will update it it should show that message so i will save this so it is saved i will go to my incident form and i will open any incident let's take an example of this one so if i just save it for now when i'm saving this you can see that it says incident number now it's not a similar number it is just picking up the random record random record from our incident table that whomsoever there is the state one and it will fetch that record and pulling up the number that's the reason we did gr dot number and it is showing right here so that is how you you work with glide record and this is the basically syntax now i will explain you a little bit more so if i go to my script again so this is my script i will make it big screen so now let's start with this now this one is you are creating an object basically to store rows from that table that is what you are doing here every time you want to play with the tables you have to start with this particular line so you have to create a glide record object to perform all these queries so the next thing is your condition now this one or you can also add more condition this is something condition adding condition now this is just one condition as of now now you can also add one more condition if you want and that can be go for the next line you can do gr dot add query and you can also see it says name or the value that's what you have to put so i can pull put any field i want so maybe let's take an example that i can take maybe short description short description so wherever i have short description is test it will again put basically pull one record but this time i'm making it wild let's see what exactly you get in info message so i'm putting the semicolon and i am saving this when i'm saving this now i will put something here and save this you can see we have this 4 3 that is what it has and if i will check here and if i go to your incident so i do have this test so there's there's only one record which has this short description so basically it is not contains the exact short description which we mentioned in the query and that's how it queries so if i go to my script again so here so this is the query so we are just building the query and putting the conditions here after that when you are done with the conditions you do and execute the query here so whenever you are done with the conditions now you want to hit and query the uh table which you have mentioned at the top then you will do gr dot query now it can also be different as i mentioned the variable name can be different and you can't have in the same scripting you can't declare same variable so this screen will automatically give you some errors that hey you cannot you use a new variable because it was already been declared so you uh you have to use a new variable rather than the old variable which is already declared then in that case then we have while gr.next that means what exactly it checks basically it process the return records that means if whatever record i'm getting and then we'll check do i have a racket it says gr.next it will loop and we have while loop so it will keep on looping till you're done with all the incident number you have as per the query you have mentioned here so it will check each and everything and whatever activity you want to do and that's how glide record is utilized so for example you want to fetch some records and you want to check if these are the records in the table then do this that is how you utilize clyde racket now this is and condition as you can see so it says state is equal to 1 and short description is equal to test now what about or condition so in that case we will remove this and i will do one thing i will do where add or equal to gi dot dis i will put here add or dot now you can see we are getting add condition or we also getting add or condition so if i select this one press enter here i will put our condition or can be that will again be state for example state comma and let's take we have 6 and i have seven that means closed and resolved both now i am fetching the records and what we will do we will also type gr dot state we will also type their state so we have gr.state get display value so if i type here and i save here so it's saved and if i go to my incident and just try to save it again you can see we have closed resolved or closed but we don't have any resolved one and that's the it is not showing you in the list but it is showing you all the closed incidents we have in our incident table that is how you put or condition now another best example of glide record is encoded query and i would say that's really strong method we have for glide racket now when exactly this glide record is used so let's take a look so in that case what exactly you need to do let's go to your incident list now you might get some uh requirement from your customer or foreign client that you have that filter so what exactly we have is encoded query and how exactly we use it so for example i put like caller is show matching so now we have all the incidents from damien and i will put only in progress so i will do show matching again so now i have incident from damian and stayed in progress and active is true that is what we have what i will do i will right click on here and i will copy this query and this is what you utilize in encoded query of client record so i copy this query and i go back to my code so here's my code and what i will do i will just make them comment and here i will do gr dot add encoded query this is the method we have we will put here the same query which we copied over there so we have copied this query and just pasted it here now i am going to save this you will see some difference so if you remember we got two records over there in our list when we queried or when we put the filter condition on the list you should get similar results right here as well so let's go to our incident and i will cross this and now i will save this you can see we just have two incidents 41 and 29 they just ran the query and we got the results as per the condition as per the encoded query we mentioned so this is the utilization of encoded query so if your customer comes with any requirement where you can get that required with the help of filter and then it's really easy to to try to find out different operators because if you remember i put state comma then one now there might be a lot of queries you have so rather than putting up or finding it out all the operators and and creating a custom query you can just utilize encoded query and then it would work without any issue you can also get the single record without add query so in order to do that let's go to your script we have here make it bigger screen let's make it as comment now in order to get the single record what you can do you don't need this query i will also make it as a comment i can just do gr dot get and if i do get it says defines a glide record based on the specified expression of name equal to value so if i do this and i do current dot cis id so the current racket which i will update i will get the number here so let's try if it's working and i do not need this so i can just remove this and i can put this line like this and save this i will go to my incident cross this i will try to save something now it should print our this number so i'm saving the record yes we got the state and we got the same number so as you can see we we did not do any kind of query and without querying using uh dot query and add query we still got the number table was still able to fetch the record from the table so the get is only used when you want to fetch single record and in that name value basically we mentioned about that dot get basically you have to put the sys id that's what you have to mention over there and when you will put the society it will automatically fetch the data for you and show whatever fields you want to fetch for that particular record now with the help of glide record you can also do counting of the records so in that case you will go back to your business rule make it bigger and we will uncomment this and i will continue with this and we will make this as a comment here i will do while gr dot next and curly braces again and now i have to print the row count now how exactly i can do that in that case what you can do where counter that is rows it's gr dot and i can do get row count now this will give you the row count and here i can mention row count count r and i am saving this so if you remember we had two records so let's see what exactly we get i'm just saving here so we get row count equal to two now why we're getting this two times because it has two records so the iteration is two times and that's the reason you're getting this in this case you can also get the number of records in that particular table you have with the condition you have mentioned you can also fetch the overall count so let's do that in that case i will change the query a little bit so i will do like this and i will just do the query that's it all the whatever incidents we have let's let's try to uh check the count in that case i don't need this uh complete so i will make it as a comment and here i will do gs dot add info message the row count is and i can type count ah so it will add this and i can just save this now it will query all the records and show me the row count so in that case because we don't have any kind of iteration here no loop it will just query and show me the numbers that's it that's what it will do so i will go to my incident cancel this message try to save something so that my business rule can run you can see we have row count as 96. now in that case if i just do all you can see we have the right number so it gave me the right count whatever i queried on incident table now in order to do aggregation now this is something like aggregation like you are doing a count of incidents yes you are counting the number of incidents in that case there is another way to count and do the aggregation so basically whenever you have to just aggregate or count the number of records in that case you should not or you should avoid basically glide record because service now has create another object that is glide aggregate object basically it does the similar thing but it just uh does that activity just for accounting so it it will save the performance of the system so rather than doing the glide record you can utilize glide aggregate and how exactly you can do that let me show you that so you will go here now i will make the comment from here i will make every line as comment so that you can understand so i will rise i will start from here so for aggregation basically what i will do i will again create a gg just a variable syntax is quite similar not quite i think it's it's almost similar so we will type this glide aggregate we will put the table name incident so i will show you the similar thing which we did with get row count so i have this so and that's the reason i am showing you this particular object because as i mentioned whenever you have to do any kind of scripting which needs to count the number of records do not use glide record just go with glide aggregate if you are already doing glide record in that case you need some count then you can definitely utilize that gr.get row count but if you are just doing some aggregations in that case do not use glide racket because this this is much better than glide record it's all about performance so here i will do agg dot i will do a query you can also put the conditions but we are not putting the conditions here and i will do a gg dot get aggregate this is what i will get but i can save this particular value somewhere and that would be vr count records so i will do agg dot get aggregate and here what exactly it should aggregate that that is the most important thing so i will do one thing that we need to use cr where agg dot add aggregate this is the important one so i will do dot add so it is not automatically coming so in that case i will remove just one let's see if if it comes and the reason it is not coming because we have put in there so you got to declare it again so agg you have add aggregate and here you can put count and here i can do agg dot query so then you can just declare another variable maybe it's count r and that is zero now we will do some iteration and that will just checking of the racket so we will do a g g dot we have next now this will count the records and here what i will do i will do count r equal to agg dot get aggregate and here i can put count now after that i can do add info message the number of brackets we have in incident table and i will do plus count up and i will save this so i will open the incident let's open this one and i will save now you can see we have similar count as you did get row count we got the similar count here as well but just the syntax is different there we use glide record to get the row count here we got the number of records with the help of glide aggregate so as i mentioned earlier the best option to do the aggregation is glide aggregate this is how you can utilize glide record in service now and write a business rule or server site code with the help of glide record if you want to fetch some records play with the records and do some database operations in this session we are going to learn about schedule job as this is a follow-up session of developer training schedule jobs are the most important functionality in service now for any developer so starting with what is schedule job a scheduled job is an automatic part of logic which executes at a specific time and can be reoccurred with some frequency any action which needs to perform at a particular time should be accommodated with scheduled job so if you have a script which you want to run with some frequency or there are other other kind of requirements as well like if you want to run a report or if you want to execute a script execute a server side script or you want to generate a record from a template now these are the things which are needed and which can be accomplished by scheduled job but in this session we are going to mostly focus on execution of script because this is a development training you must have learned about scheduled job in your admin training as well schedule job states now in order to understand scheduled job its states are really important because when you run a scheduled job it goes to a different states so whenever you trigger or it it is running or it it gets done those are the states you have in the progress of scheduled job so we have ready state that means that job is ready to run we have running if that job has already started and it's running queued that means it has queued up so there are some other uh jobs which are still running and this job will be queued into that particular queue to run once those jobs are completed then your job will be running then we have error that means while running the job if you got some error then it will show the state as error schedule job module now in service now in your personal developer instance if you will see under system definition you will find schedule jobs this is the module where you can see all the skilled jobs you have in your system now out of the box if you will click on this particular module you will find some existing scheduled jobs and those are basically existing baseline schedule jobs which are already being created by servicenow and if you really want to create new one that you can do with the help of new button and you can submit the form and you can create the skill job schedule job tasks now what kind of tasks you can fulfill with the help of scheduled jobs so you can you can perform the tasks like generation and distribution of a report generate a racket from a template you can run a script you can run a script to create a report and the generation and distribution of report as you can see if you will try to create a scheduled job it will automatically show these options first when you will click on the new button because system wants to know what exactly you want to automate what exactly you want to schedule as per the requirement and the important part for this session is automatically run a script of your chosen so if you want to execute a script it can be any script like glide racket or maybe counting of records if you want to do it after every 15 minutes or after every 30 minutes or maybe every week or it can be other tasks as well so any task which you really want to run every time you want to keep on checking what exactly going on in your system and it can happen you might get a lot of requirements around it which is based on scheduled job now one of the important factor which you have to remember while creating skilled job is performance because if you will create multiple scheduled jobs in that case your system will keep on utilizing the resources so it's not recommended that every time for every requirement you always go for scheduled jobs schedule job form now in order to create the skill job you have a form so when you want to have schedule script execution then you want you will have some fields where you can fill and then you can run the job and that's kind of configuration of your scheduled job so if i start with like you can see we have this name field and that is the name of the scheduled job and this option this form you will see when you will click on automatically run a script of your choosing so that means under system definition when you will go to schedule jobs and you will you will click on create new button in that case that once you click on new button you will see five or six options and you have to click on automatically run a script of your choosing so the first field we have is name of the scheduled job then we have whether the scheduled job you want to keep active or inactive and this is really important flag here then we have triggering basically that when exactly you want to run this job do you want to run daily do you want to run weekly monthly that's how you can decide here then you have time so if you have selected for example daily it will give you an option to select the time as well that at what time you want to run it maybe you want to run it periodically maybe after every two hours after every 30 minutes that's how you can select and this as per your requirement as per that task you see that this can be fulfilled by this particular frequency and then you can select that frequency this is just the application scope then we have condition condition to run the job that means if you want to add some specific condition it will open up the script section basically for you and if you under run that this particular script should run at this particular condition that you can mention on condition and then you have the most important part is run this script that means the script which you want to execute for the scheduled job that's what you can mention here whatever line of code you have you can mention over here condition script now conditions kept plays a really important role because condition is uh condition field is selected if scheduled job needs to run after beating a condition it's a server side code so basically when you write a code in in skill job that's a server side code and you cannot use current or previous like you can do um if you if i talk about the record level you can you can always use current and previous if i talk about business rules you can definitely do that that's a server code however you cannot use current and previous in scheduled job now if i talk about the condition it should always evaluates to true because if that will be true then only your scheduled job will run now let's take an example of of scheduled job in personal developer instance i will show you all these fields in personal developer instance i will also try to run a scheduled job and i will write a script into that particular field so that you can see how exactly the scheduled job works so let's do let's move to my personal developer instance and see how skilled jobs work this is my personal developer instance i will go to system definition under system definition i can see this option schedule jobs if i click on schedule jobs you will see all the baseline schedule jobs now these are not created by me these were already created by servicenow now if i talk about the numbers now numbers can be different for every individual instance it depends the kind of functionality you have enabled it might happen that you have enabled a new functionality a new plugin which might have an extra skill job so i don't want to say any numbers here so it can be 116 in my system it can be different in your system as well so don't go with the numbers but the only point is if your instance is fresh and you have not created a single job then whatever skill jobs you will see under this module they will be out of the box so let's let's click on create new so these are the five uh basically five options uh which you can try to automate because it's scheduled job is kind of an automate right because you can just sit behind and you just write a script or write a code and it will automatically run at a particular time and that's how you're saying it is automated for example sending an alert after 30 minutes or maybe after every 30 minutes that's kind of thing it's kind of automation you don't need to be present for the system so you can see we have automatic automate generation and distribution of report uh creative racket from the template automatically run a script of your choosing this is what we are going to select as part of our development session if i click here so this is the form which you were talking about now what i'm going to do i'm just giving you the demo so here i will just type demo scheduled job for youtube this is what and here's the active flag when exactly you want to run this that you can mention here maybe weekly maybe on thursday that also you can select so there's a lot of other options so you don't have to look for any any kind of odd condition but but the thing is if something you want as a condition that is here if i select this box as true you will automatically get this particular field called condition now this is also a script so you have to mention the script as i mentioned the server side code you cannot use current and previous the important point here is when you will write the condition mostly i would say you will mostly use like uh glide racket or maybe all the date and time um like apis we have the methods we have from service now that's how you can mention here but this time i'm just i'm just removing this and here the field where you can write this script so once everything is done and you will write the script here that script will run when this job will execute when this java will start running that that particular script this particular script will execute basically or whatever script you are you are mentioning that's how it will it will automatically run at that particular time let's let's take an example if i if i talk about uh the count of incidents so let's count some incidents so i will i will write a script here just where gra new new glide aggregate and i will put incident here i can just mention the g r a dot add aggregate and i can put count and then i will just because this is the aggregate api we have then we can put gr a dot so we will put some condition and that's add query and i will put state what state will you want to have maybe let's take an example six or maybe seven then we have jra dot quality and i will do gra dot next here i'm just going to count the records maybe just i just want to count the records every day so if i will put here and i will just mention for example gs start lock now i'm going to log it count of records i can put plus i have gr a dot get aggregate and here i can put count maybe before that you can you can first add this value so you can get this value somewhere let's just just mention uh now get the value somewhere so if i will put like count where count incident equal to zero incident here i will do because you have to calculate it so i will do count incident equal to this grade or aggregate i can just format it i don't i don't need this one and here i can just put g start log the count of records is here i will just put now what this will do this will just automatically count and it will automatically every time as per the frequency i will mention here it will keep on pushing the lock now when i click on save you will see some more buttons over here as you can see we have this execute now button now regardless of whatever frequency you have given on the form on the configuration of a scheduled job if you want to test it whether your script is running or not that you can do with the help of execute now it's kind of a testing now i want to run this script which i have written right here in that case what i will do i will click on execute now but in before that i will do one thing i will go to logs this is the logs uh one i just want to make sure that i have opened that log transactions in the next tab and i will execute it when you will execute it that script will run but let's try to refresh it says undefined so basically it ran but it is not showing it that's why let's try let's see what happens i go here so i will go to my definition so i'm going to check my script again so it says state count add aggregate so apparently it should run let me check it i'm executing it i go here try to refresh i have get aggregate this is correct just lock i think everything is correct but why it is not running there here curry okay let's try this if particle two and then i will put seven i'll save this and now i will run yep i have this so now you can see um our script ran and it says count of records is 27 and if i refresh this okay so even it i think last time it ran so maybe we did not refresh our screen but even last time and even before that it ran now you can see we ran it three times basically and every time it was running but maybe we were not able to check the locks properly i thought it starts not running because of some condition or something idly whatever i corrected it should still work as it is but i just thought just to fix it but yeah anyhow we got the record so we have around 27 records now if it's just a logging i did but it might happen that you want to trigger some notifications maybe uh there are some days like overdue maybe you want to send some alert if system checks that after five uh the date which is mentioned on the field is like before five days and that you can check only with the help of scheduled jobs now this is the main reason that why you need schedule jobs so that you can automate something and it it automatically runs at the same time with the same with some frequency which you have mentioned for your script and that's the reason you use scheduled jobs now another thing about scheduled job is how exactly you find that where how what are the what are the what exactly the status of schedule job is so let's take a look if you go to your instance and you go to system scheduler here you will find we will see scheduled jobs and if any job which is scheduled to run for today you will see in this particular window so if you click here you can see it says next action on today that means whatever frequency you have mentioned for these jobs they they are supposed to run at this particular time on basic today because because of this filter so that's the reason it always updates this next action time and it can be any time it can be day after tomorrow as well but that won't come here because of this filter but every job will be here at least next action today and if i talk about scheduled jobs here you can see what all schedule jobs are running uh whether they have ran they're ready any error that's how you can see what are the frequency next action everything here and here you have slow job log so any job which is running from a long time or maybe it is taking a long time to run those things are are being displayed here and it is really really needed to troubleshoot on different kind of things if for example the performance is slow so you can always look for these transactions and what jobs are running very slow because they're also showing you the response time and it's also showing you the business rule time so everything is here it says sql count as well so whatever jobs are running very slow you will see here in that case you can take some action maybe you uh you might decide if it's running daily you might decide it some maybe after some time that's how you can decide with the help of slow job log so if any job is running or is supposed to run in the future that's how you can see under system scheduler in this session we will talk about event management now as part of developer training even management also plays a very important role in servicenow platform because if you want to manage events and you have different events which are generated and how exactly you respond to those events that's how you manage with the help of event management what is an event a triggering point for any action or operation it's kind of an indication that something noticeable has occurred example user has logged in a record is viewed inserted updated deleted or queried or you're putting some error or warning you're logging some kind of information warning or error so these are the examples of an event how even works now all these events when they get generated in servicenow you can track them and you can also perform some operations that means you can respond to those events and how exactly you can do that so let's say if any action or any kind of operation has happened maybe a record is updated or any particular field is updated because that's kind of an event in that case you have to capture that event that means you have to create an event first and that's called registry of an event because that activity that particular event has to be captured in the event registry because you have to mention that yes this is kind of an event which i have to capture so you have created an event then you have to generate that event and how you generate that event you generate that event with the help of script with the help of business rule and then with the help of workflow now these are the three different ways you can generate events and the next part is because you have to perform and respond some uh respond to your events that means you have to perform some action as well but after generating the events you have to add them in event queue that means then your even manager can process those events and then we have script actions and email notifications to respond to those events so once event is added to the event queue then it will be processed that means that if event has been added what exactly you want to do in that case you can sell send email notification or you can write script actions maybe you want to do some some kind of scripting and you can take some actions or respond to those events whatever being generated event registry now when you want to process the events as we mentioned you have to first register that event and how we do that with the help of event registry so here you can see we have event name then you have table for which you want to generate that event then we have application that means scope and then queue now this queue if you will leave it as a blank then this event will be added to the default queue when you will generate it however if you will mention or you will create a new queue then this particular event will be added to that particular queue automatically and as a best practice if is as part of your functionality if you're thinking that this particular event or whatever event you are creating will be generated frequently in that case as part of the best practice the recommended approach is you always create a new queue and add that particular event to that particular new queue rather than using the default queue of servicenow platform then we have fired by in fired by you mentioned about that how exactly uh this particular event is generated maybe you can mention with the help of business rule maybe any kind of a script or any kind of workflow that's something you can mention in this particular field then we have description here you can just mention and that what kind of details you can mention about just little bit details what exactly this even does maybe and when exactly this is being fired so fired by is how it is fired and in description you can mention when it is fired maybe that's how it just to explain it about this event now once you are done with the event registry the another important part is generating events so you can generate events in servicenow with the help of glide system method that is gs.even q method so we have some parameters as well in gs event queue so you can see we have event name that's the first parameter you have to give then we have object then we have to give some optional parameters and those are like pattern one that's kind of a it will be called as a string so that if you want to pass any string that you can use in pattern one and pattern two the pattern three would be the queue name so if you are creating or if you want to add this particular event into a queue custom queue in that case you can mention that particular queue name and if you will not mention anything that means this will be added to a default queue automatically generate and process an event now here i will show you an example that how exactly you can generate and process an event and perform and respond to those events let's take an example of incident racket in incident racket we have short description so for example if that short description is updated that's kind of an event now once that shot description is updated that means changed in that case i want to send a notification to the caller the current caller so this is my requirement as part of this even generation now how exactly i will achieve this so for that i will go to my personal developer instance first i have to create an event that means in registry i have to create that event so i will go to events under system policy you will see i have events and then i have registry event log and then script actions i will click on registry now this is the list of events these are all out of the box created by servicenow so these are all baseline events so what i will do i will click on new this will open up the registration of event so we have the same form which i was showing you earlier we have event name so here what i will do i will mention the name as incident dot short d dot updated and i will mention here the table that's related to the incident this i will leave as it is this is just a default application scope this is the queue i'm not going to mention anything right here uh caller access you don't have to worry about it this is just cross-scope privilege that's what you mentioned as part of servicenow platform functionality so you don't have to do this is not related specific to event then we have fired by here i can mention business rule and then i have description here i can mention when short description gets updated i will click on save so in this case i am going to create that even registry i have registered that particular event because anyhow this event is creating that means system is definitely doing that action but i want to capture it so that's the reason i'm registering this event because i want to respond to this event and that's the reason i have to register it first now after registration now you have to generate this event and how do we generate it maybe with the help of scripts workflows and business rules in this case we will use business rules so i will click on business rules right here now this will automatically take me to the same tables business rules which are active you can see right here now i what i will do first i will check do we have any kind of a baseline even generation business rules so ideally the answer would be yes so if i will search for that yes we do have incident events so now it's up to you whether you want to use the same business rule or you want to create a new business rule ideally you can use the same business rule but the only problem is if you will touch this then you will not be able to um upgrade if servicenow will perform any changes yeah you can do that with the help of upgrade history however this would not come under upgrade then that's the reason and it's it it's not just with this business tool it's any baseline functionality you change and if you touch it then servicenow will not be able to update that particular functionality so but you can see the kind of uh conditions we have like you can see we have when that means after insert and update that means when record incident record will will have some insert or maybe some updation will be there so in that case what i will do i will go to advanced now here we have we can see a lot of events have been generated that means we are adding a lot of events to the queue manager so what i will do i will add my event as well and i will write here sas demo and i will start with if because we have to definitely put the condition that why in what condition i want to generate this event and that condition should be current dot i have short description dot changes just changes that means if short description is getting changed then i want to generate an event so and how exactly i will do that i will write gs dot even you will type event you will automatically get this and you can see it says queues and even for the event manager that means it will generate that even and add that even to the q event manager i will press tab now it will ask me for different parameters you can see i have like name then record that means the object panel one pattern two and if there is any queue in that case i will give the name of the event first so we created this event i will do short d and i have dot updated i will do comma here i will just do object that is current and then i will ha i have to mention the pattern one but now here pattern one we can mention maybe the caller so i will do current dot color and then i will do comma here you can mention the new value maybe so current dot then i have short description so this is the new shot description and i will do semicolon that's it so i have generated this event so i'm going to add this event to queue manager with the help of my business rule so what i will do i will save this i have saved this now so the first step was we created we registered at an event we are done with that after registering we have to write a script to generate that event we have we are done with that as well now the next step is respond to this even that means whenever this event would happen what action i would take so as i was telling you we will send a notification in that case i will go to notification i will go to notifications here i have notifications and i will create a new notification when i click on new i will just mention short description change notify table is definitely incident table now this lesson is not about notification so i'm not going to train much about notification here i will just select event is fired because we want to track that event here i will find my event and if i type incident dot you will definitely see incident dot shot d updated so this was the ins uh event which we created so if you will first register it it might happen that sometimes developers go into uh the same uh record list and then they're not able to find it because they have not registered any event but you will find another events as well but in this case we are using our new event which we just created now what we will do we will go to who will receive maybe here and what it will contain and i will go to just advanced view because in advanced view you see more options so we have even param contains recipient okay so if we have that so i will check this because we want to send it to the caller of that particular incident so in that case i have mentioned this one it's up to you because i'm just using that even param1 contains recipient so i'm just checking that box i don't have to do anything else because i'm not sending to anyone else as of now um then i will do what it will contain in that case i will mentioned short description updated and i will mention here just hey i can mention hey your incident shot is update head and you can mention the new one and that is definitely short description that's it because it's just an example so i will save this so i have saved this now i will check whether i have notification enabled so i will do email after yeah i have to enable sending that email again so maybe gaurav ameri prize at gmail.com okay so it's go overbeardprice.gmail.com and i will save this once you will save this all your emails will be sent to this email address so what i will do now i will go to incident now we have not mentioned any kind of uh condition like any other condition it can be any any incident so let's see it's we have david miller i will open this incident because now we are checking and validating that how that even processing is working um here here we have uh let me add i will add email uh let me see yep i think it's already updated so i will do one thing i will try to change this and that will be changed change the shot description so i have changed the shot description and i'm just clicking on save once i click on save now this is updated and we will see whether it is sending the email ideally it should do we can check the email logs i have emails and yes you can see so email was sent successfully and it was also sent to david miller now do you want to see how it this got generated so i will show you if you click here and you will see this was generated because of this event that means we are able to create event and process it successfully now this is just a demo if you want to capture and process and respond to different events you can also do in similar way as i mentioned as part of my session you can also utilize events in normal scripts in business rules and in workflows we also have a script actions which we haven't talked about it yet now what are script actions so if i will go to events here i have script actions we can click on this new button so i will create a script action i will click on new button this will open up the form here i will put the name of the script action so maybe log a message when sd is changed here i can put the event name same event name now we are already generating that event name with the help of that business rule so that will definitely be there however we will mention this name we will make it active i will not put anything in the condition script now what i can do i want to log a message for the same event generation so what i will do i will maybe first i will declare a variable now i will get all the parameters so maybe uh first i will get the parameter maybe uh the pattern to uh param2 which was the current shot description the latest shot description so in that case i will do where and i will mention maybe new value equal to i will do event dot pattern one it's just a declaration and what i will do i will do gs dot maybe add info message or but i do i want to log not info message it's gs dot maybe warn i will add a warning so i'm going to add a warning here the shot description was changed change to and here i can put plus new value that's it that's it you're done with your script i will click on save now let's see what happens so this is created i will go to incident and open any incident maybe the same one email server is down this time i will make it maybe even email server is up and i'm doing it right now and i'm clicking on save so short description is now updated so this will definitely send an email and what i will do i will go and check in logs so i have all these logs right here but these are database logs i have to check the transaction logs uh that will be right system log uh let's see let's check warnings directly awesome it says short description what stains to now here we have the society that means you did some mistake now why this is showing you a society because what you can do you can go to your script action and that's a good thing i think if if you always like if you're uh if you're not able to get the right output in that case at least you know i think you learn better when you debug things so here we can here we have to do param two because in parallel one we had a caller that was current dot color so i will save this again and i will go to incident any open one and i will go to this one maybe and it says unable to post content on wiki page i will do i'm able to just i'm playing this just a demo i am saving this so this will generate that event add to the queue manager and i will go to system logs so i go at the bottom i have these warnings yes i have i'm able to post that means the current shot description which which was pegged from the parameter we mentioned in our event when we were generating it so that's how the whole event management works now one of the important part of event management is also logs so if you will type event you have this event log as well so you can check what all events were triggered so if i have event log i can maybe check the created date i will sort by create it and you can see yep so this was created i kill i will do one thing i will click on show matching you will see that how many times it was generated so you can see now this particular event was generated three times today and that's what we did so you can see it also shows you the process duration there's no queue mentioned and the reason behind it because this was added to the default queue in this session we will talk about script includes and glide ajax what is script include a script includes store javascript functions and executed on server side a script include code can be reused in different scripts of service now you can call script includes from client side which is an ajax call and referred as glide ajax unlike business rules and client scripts you need to call script includes from another code to run the code mentioned in it let's see script include form and its fields first field is name to identify script include then we have api name which is the name of the scope and script include name client callable you can check this box if you want to call script include from client side like client script code active you can check this box to enable or disable the script include description details of script include the main field we have is script in this field you have to mention your code to run from another script out of the box a script includes service now has various out of the box script includes created for different features and functionalities this is my personal developer instance in order to see a script includes you need to go to system definition you will see this application under this application you will find a module called script includes if you will click on script includes you will see list of script includes available in your instance click on new this will open new script include form and here is the script field where you can write your script which can be called from another script types of script includes there are three types of script includes in service now first one is classless in this type of script include you create one function which you can call from another script and you don't create any class in this kind of script include and this basically runs on server side second one is extend a class in this type of script include you need to extend another class like abstract ajax processor which is a another script include and you can extend it and call it from client script and third one is utils in this type of script include you can create a class and add multiple functions which you can call from another script and this can also be called from client side classless script include this is how you create classless script include which just has a function which is called from another script in this case you're not creating any kind of class that means it is a classless script include in my personal developer instance if i go to script includes click on new button and here i just type demo test i'm just giving it a name i press tab you will see this class is created automatically that's a functionality out of the box you have in service now but what i will do i will just remove this whole script and rather than that what i will do i will just declare the function so i will call the function here we have this demo test and i can do a comma b and here i will give for example c equal to a plus b and then i can do gs dot log i will do gs.log the addition of addition of plus maybe i will take a and here i will mention uh a plus here i can just mention plus space like this because this is how the string would be and i can do plus b and i will do plus and here i will do is space and i can do plus now this is a class less script include now i can call this function from a business rule and you will see the results how exactly it works so in this case i will maybe i have given demo test demo test here c equal to a i think um i will do there as well because that's why you have to declare it's a c variable now a and b are the parameters now here we are just adding it is kind of an addition we are doing now how exactly we will get these parameters values so first i will save this let's save this and then you will understand i have saved this what i will do i will go to business rules and i will create a business rule here so i will just click on create new so i'm going to create a business rule to call that particular script so here i will just maybe uh give a name that is demo maybe let's give demo test as well or maybe a script include classless that's what we are learning classless demo that's the name we have given and here i'm just selecting a random table maybe incident because i want to run that so for that i will just select incident table and i will check this advanced check box and i will select when and this can be before and it should be before update so before update of any incident i will go to advanced because we don't want to take any action for now my only action for now is i want to calculate that value or whatever value we have written in that log that is something we want to populate so in that case what i will do i will send a parameter and i will actually run that code how exactly i will do that so here what i will do i will do where a equal to 10 let's say it's just an integer i'm giving verb equal to 90. now i am going to call that script include the function which you have created how exactly you do that you just need to write demo test that's a script include we created that's a function we have as well so in that case i will just mention a comma b because this is the parameter we have to send it that means value so a and b value will be captured here and it will be sent to that function we have in our script include so this is done and what i will do i will save this now how exactly you can test this in order to test this you have to just update any random incident so maybe we will go to incident so let's open any incident we have let's say this one and we will also just just open logs as well because that's the reason we have done gs.log because our results will be saved in the log so maybe i'm just writing here test and i'm doing save and this is updated so if i go to logs because we can't see results anywhere else because as of now we can see the results in the logs that's what but you can you can definitely utilize this anywhere you want so i'm going to the logs and you can see we have this result the addition of 10 plus 90 that means it automatically took 10 and 90. this is the one we put in our script include and it is it is also showing the value 100 that means your script is running without any issue you are able to call a classless script include from a business rule but that's how you can work on classless script include script include with class now this is slightly different so this is how you create script include with class in which a class is created and function is created in the class light camera action script include with class this is how you create a script include with class in which class is created and function is also created in the class and you can call both script include and the function directly from another script you will see the same example in my personal developer instance but this time we will use class so in my personal developer instance i will go here and i will go to a script includes again and i will just sort it out with here we have demo test so i have just sorted this out with the updated date and time so i am just clicking on new here i will give a name demo test class i will press tab so if you remember it will automatically create the class for you you don't have to create yourself now in this case you can see we have this class under this class we will create a function so i will just do function and i would do demo test a comma b same script no difference i have to put comma here and then i can do where c equal to a plus b or maybe this time i will do b just to make a difference and i will do gs dot log and i will write same thing what we wrote over there the addition of plus a now here it says unexpected token demo test okay we can just i think i just did a mistake uh i will show you quickly why i did a mistake you always define a function like this function that's how you you define it so i have created the function now that's that was something different we created and this is how you declare it in a class so we have this function demo test and here i will mention addition of a and i will do plus and here plus b plus and i would do is plus and i have d that's a result so that's what we have gs.log and i will save this let's save this one so i have saved function what we will do we will utilize the same business rule which we had so if i go to business rule i have this business rules here let's sort it out to see our listed latest business rule we created this one so in that case uh we we we have just called that demo test but that's that's not you have to declare here this time you have to call that script include and then you can call that function so in that case what you will do you have to do where you have to create that particular scripting code you have to declare that here so i will do where maybe i will do v equal to i will do new now i will provide that script include name because you are going to access you are creating the class for that particular script include which you had over there so i am going to write demo test class that's what we had and if i go here i do v dot demo test and i just give that's it you are done you have called that so in that case i will just save this and let's see we get the result or not so i hope we have our names are correct so you have demo test now i will go to any incident i will come here and just try to update any existing incident updated and if i come here this was 705 i think this is showing us time and yes we have this here as well so we got similar result but this time we have used the class so that's how you can use classes and script include so you can use classless as well and you can use class as well it totally depends the kind of requirement you have because in in class you can create multiple functions because in this case if you will use classlist in that case you will you can just declare one function over there and you can just call it from from your business rules or server side code but in this case in classes you can add multiple functions and then you can call those functions from your any different scripts you have calling script include from client script so once you create the script include you can call it from client script you create a glide ajax variable in which you have to call script include then you add parameter to call the function mentioned in script include then you also add a parameter which you want to send to script include so you capture it on the client send it to the script include and then you make a asynchronous call to your script include like ga dot get xml and you also define a callback function which you have to declare here and then you call that callback function which returns the data and store the value in answer variable so whatever parameter you sends to your script include it returns that data after using that parameter and that results are basically captured in this variable called answer so this is kind of a syntax that how exactly you can use glide ajax in service now let's create a script include with this glide ajax so i will go to script includes click on new give it a name as demo test ajax i will press tab when you will press tab you will see this class is created now we have to make this client callable the reason behind it because we have already talked about it glide ajax is something you call it from client so i will make it client callable when you will click on client callable you will see the difference that this will extend this particular script include now abstract ajax processor let me show you quickly so that you will understand what exactly it is that because abstract ajax processor is another script include and we have in our system out of the box see we have here abstract ajax processor hit this one i think it's it's at the top so we have this abstract ajax processor which we are extending so if i go here and you can see we have this particular uh this particular class so now we will write a script so we will create a function so i will start here we have to write in this particular place so we will start with i have to write the function so i have to declare a function so we'll write demo test function and here i will write function now i'm not getting this parameter from server side right now we're getting this parameter from client this time i will show you how exactly you do that you have to first close the curly braces and then you also put this comma here for each function you declare you have to put this comma then i will do one thing what what we will do we will try to uh populate the user id uh user name and in uh first name and last name let's see that that's what we will do so on incident form if you select the caller uh we will populate uh the first name and last name of the user so in that case what we will do i will just type where user id we will do var user id equal to this dot get para meter now here you are putting the name of the parameter so which always starts with cisperm underscore and then you can give any name you want so here you i am putting like user so whatever parameter i will get from client it will be saved in user id the variable which we have created this user id now i will do where gr equal to new glide record and i will do says underscore user because i'm going to search that value which is coming from client i will search in users table so that i can get first name and last name and then i will populate that now this is just a demo for for just showing you how exactly you can use this kind of glide ajax because overall you already have some i think api so that you can directly call and check first name and last name that is out of the box but i'm just showing you this demo just to show you the example that how exactly you can use glide ajax so then we have the sys user and i will do g r add query i will look for the society which i will get from client how exactly i will get that society i will show you in a while here i will just put user id that's it and then i will do gr dot query if that is found in the table if that user is found next and then i will do where a equal to gr dot first name that's the name of the field we have and then i have gr dot last name i'm sure these are the names we have field names on on user table and then i will just do return so now here you are going to return the response which you are capturing in this variable so i'm returning a so whatever value we have it will be returned by this function so i think this is it i will just save it now what you have to do you have to call this script include from your client script so i will go to incident maybe so let's go to incident and here we will write a client script so i will come here and i will go to client scripts and i will click on new button new client script form is opened and i will give it a name maybe demo test ajax so that you can understand uh type this this something we will put on change and i can just put caller and here after here we will write the script now once once you will create the script include you have to call that script includes now that is as of now it is a client callable however you call it from here from client that's the syntax we are going to use v-a-r-g-a you're going to create a glide ajax variable first so i will do new glide ajax now here you have to give the script include name so if i come here and just go to script includes so i have this script include let's go to updated one latest one we have this demo test ajax i will just open this and we will just copy this and put it here so this is the first step you have to create a glide ajax variable now you have to call that function which you have over there that's the add perm that's that's that's what you use so here you will define it as let me you will start with cis perm underscore name that's how you call that function uh so when once you are declaring that script include now you have to call that function how you call it you have to mention it here so i will come here and i will copy this one and i will put it in the string and this has to be string so semicolon and i will do ga dot now here you have parameter you can add multiple parameters but in this time we just need to send the cis id of the user who is in the caller field so in that case i will just do add param and here i will just put the same parameter which we had over there that says sperm underscore users if i will take you over here you will see we have same parameter so this should definitely match so we have that parameter i will do comma now what parameter value should be there so you have to get that value that value will be will be basically you have to just put new value that's what you have you're already capturing it on change that's a functionality of on change client script so here you have that value available in new value and i will just put semicolon and now i will do a asynchronous call and asynchronous would be getxmlg.getxml and i will have callback function so maybe i will just type callback function you can just keep your name as it is as as as per you want so that is not restricted this is not part of the syntax the syntax we have is this one this one can be dynamic which you have to call this script include uh this one is not dynamic till here but this is something dynamic you can change the name as per the function you want to call and this is something the parameter till here it is definitely static but this one will definitely change this one can also change as per the parameter value you want to send to the script include to process the script you have in your script include callback function that definitely you can have your own uh name whatever name you want to give we will do it now we will call that callback function we will have call back function and here we will put the parameter response so this is something we will get from that script include once it will be processed you will get it and here i will do where answer now this is also part of the syntax when you start their answer so you're going to create the answer variable and you will store the value the response you will get it from your script include so we will do response dot response xml dot it is also capital letters dot document element dot get attribute so we have this till now everything should be same nothing should be changed this is this is the part of the syntax so accept this so whenever you call any function you put there rest should be should be always same then you put here and then you do i think you have to do alert okay that's what you want you want to show that alert so i will do alert and i will just put answer so whatever answer we are getting getting from script include once it is processed it will be stored here and then you can utilize that value anywhere you want so we i'm capturing that value and let's see what kind of answer we will get so here we have alert answer and we will save this and if i go to my script include this is what we have here and now i can i can just do a test so let's go to incident form i will click on create new and if i click on create new and i just select any user here let's say this one and we got the answer you can see it is not returning the value there there should be definitely some issue that it is not returning the value so we are doing gr.next we are selecting here sperm user demo test function i think the name is also correct get parameter is also correct new glare record add query everything is fine add query we have sys id i'm putting that okay we have done one mistake so i will go here i do remember now but it is not returning that so i will go to my client script again maybe that value is not coming so let's let's check that because it is returning answer we have this alert with the reason behind it because you have mentioned is that as a string which you don't have to answer is a variable so it should definitely show that value now so let's save it and i will click on create new again i will create a new incident and select a caller and let's see if i'm getting that value on the client from server so i will just select here maybe abraham lincoln yep we are getting that you can see there's no space because you have not mentioned that space but overall you are getting server value on the client so this is how you always call a server server-side code on the client that if you want to fetch some value on the client you always use glide ajax there are some other ways which you have learned in my other videos like get reference we also have g underscore scratch pad but glide ajax is the recommended and the best approach to get the server data on the client let's see some practical examples with live i will also show you how can you use script include in other places like reference qualifier or business rule conditions starting with first scenario on problem form there should be a field problem owner and user can only select those users in this field who has problem underscore manager role this is my personal developer instance now before i create that script include to fulfill this requirement let's add that field on problem form first so i will go to problem application and i will open a problem form so here is the problem form and we don't have that particular field available because that is not out of the box so in that case i will go to form layout and create that field so i will type here problem owner and this will be a reference field and this will be referencing to user table so i have this user table here i will click on add this will be added here and i will take it on the top of the form and above state field i will click on save now you will see that this field will be added on top of the form that is above state field i will close this you will see that field is created and added on the form now if you click on this button you will see that this will show you all the users available in your instance but as part of the requirement you have to restrict the choice that means you should be able to select those users you should you should be able to see those users in this particular list to select the people who have problem underscore manager role else others should not be visible in this particular field let's create a script include to filter this data i will go to script includes modules click on new provide a name so it will be prb like functions you can see this class is created i'm not going to check this box because we are not going to call this a script include from client we will call it from server side code so i will create a function here so maybe get prb managers function i will put comma here now i will create a variable so that i can store all the societies of the users who have that problem underscore manager role so in that case what i will do i will do p managers managers equal to i'll just make it as a string where gr equal to new glide record now which table you will select here you have to select the user role table basically where you can see the relationship between user and role and the name of the table is cis and underscore user underscore has underscore role and it has two major fields role and user and i will do gr dot add query we will do query here we will search for that role which is problem underscore manager for that we need society of that particular role so what i will do i will quickly get the society so i will go to role table so here we have roles and i will search for problem manager so here is the role i will copy the society i will come here and i will put that same society here in the string then we will do gr.query in this case you will find all the users with this role then i will do while gr dot next and here i will do p managers that's a variable we created equal to p managers plus we will add comma so after every user we are getting with this loop we will always add a comma after it so in this case it will do comma and then i will do plus and i will just add gr dot user now this will capture the society of the user and it will search for all the records where role is problem underscore manager with the society we have mentioned and it will populate all the society of those users so it will basically capture those values in this particular variable which we have created now with this string so what exactly you have to do in order to filter the data you have to populate that particular thing in your reference qualifier you have to push that value you have to push that particular query so that system should search the rackets as per the query mentioned in reference qualifier so what you will do here i will just mention here there and now i will store all whole query in results because but i have to make that query so i will do cis underscore id in now this is out of the box which you're using because we are searching that if society is available in all those uh all those societies which we are getting for the users then it should filter accordingly so this is the query we are creating so i will do p managers and then i will just do return result and i will save this so once it is saved now i will apply and call this script include from our reference qualifier so basically we will go to the dictionary of that field to filter the data so i will go to problem form let's open any problem form i will open this one here we have problem owner i will go to dictionary now here we have to provide the reference qualifier basically with custom condition you will see reference qualifier here we have normal condition but you have to go to advanced view so that you can see more options for reference qualifier so you can see here we have this reference qualifier as of now it's simple but we have to make it advanced now here you have to mention and call that script include and your function so we will start with javascript colon we will do new and then i will first put the name of the script include so the name of the script include we created let's check that quickly we have this prb functions so in that case i will just copy the name here i will come here and i will put that here and then i will call the function the function which we have created so i will copy this one as well put it here but that's how you call a script include and its functions so i am putting this in reference qualifier i'm saving this you can see that it is saved and you have put in this reference qualifier that's a custom which is basically taking the data from script include let's go to problem form now so if i open any new problem form and here's the field if i click on this button you can see that it is only showing three records to select but before we applied this script include and we changed the reference qualifier it was showing all the records of your instance so this is how you can call a script include from server side and also from the dictionary of a field in reference qualifier scenario two when user selects a configuration item on incident form then assignment group should automatically set to support group of selected ci on the client so if i take you to my instance let's see the configuration items first so if i open configuration items these are all application servers maybe i just do cmdb underscore ci dot list dot list in this case i will get all the cmdb rackets now here there is a field called support group i can just take it here in the list and i will filter out and see the records where we have the support group we have 37 ci's where we have support group available so the requirement is if i go to incident form and if i select ci and if that ci has a support group it should automatically populate here normally in every organization people definitely implement this functionality that they should have support group for every ci so whenever you do that whenever you select any ci it should automatically populate on client in this assignment group field how exactly you can achieve this now this is something we will use glide ajax that means you will get the data that server data from cmdb racket and once it will be selected here you will push that value here so whatever data you will return that support group you will populate it here so let's start with creating the script include first so i will go to script include and we will click on new and i will give it a name as set support group i will make it client callable so that we will extend this abstract ajax processor and i will create a function now so i will do get ci now this is a function i am going to create so i will do function comma here curly braces and then i will start writing so i will first get the ci the value of the ci we have on the client because that's how you will search for that record because we have to get the society of that particular ci so in that case i will do cmdb ci it's a variable i'm creating i will do this dot get parameter same syntax if you remember we used in glide ajax example and i will do cis perm underscore ci semicolon and i will do where gr equal to new glide record now table i will search for cmdb underscore ci and here i will do gr dot add query i will do says underscore id and here it should be same value so i will do cmdb ci that's a variable we have and this particular parameter value will come from the client and i will do gr dot query and if that ci is available that means gr dot next you can also do one one more thing that if support group is available then only you should run this i think that's a i would say additional check you can put so maybe i would do add query and or maybe i will just do gr dot we will had add not null so you will put the field name here and the field name is support group so if it is not none and then i will do g we will do return gr dot support underscore group so we are returning support group from this script include so i'm clicking on save so our script include is ready now i will create a client script so that i can call it i can call this script include to get this data get this support group so for that i will go to incident here i will keep this script include open because you would need that just to copy the names and i will go to client scripts click on new and here i can just give the name set assignment group set assignment group incident here i can just put on change and i can write the script here now here i have to create that glide ajax variable so i will do where ga new glide ajax we will copy the name of the script include i will put it here and then i will do ga dot add param says perm underscore name and here we will put the function name and the function name we have is getci i will put it here semicolon and i will do gr now we will have parameter we have to capture it and then send it to script include so that will be cis perm underscore ci how exactly we will get the value the value you can get same thing i think you can do new value because that's variable is that parameter is already available with this on change type of client script so we will use this and we will do ga dot we will do a call get xml and i will just call functions so maybe a callback function i can do populate group that's a callback function so we will do function populate group with the parameter response and i can do where answer equal to response dot response caps xml dot document dot document element dot get attribute get attribute and then i can do answer semicolon and this time i have to push that means that set that value in the assignment group so i will do g underscore form because this client script so i will do set value and we will mention the field name that is assignment underscore group and the value would be which will get from the script include that is just answer which will be stored in answer variable and that's a society of support group so that's it and i will save this it is saved now i will just try to look for configuration items so we will do cmdb underscore ci dot list this will open the list of configuration items we have in the instance here i will filter it out and now i'm going to select let's see this one i will go to incident form maybe i will create a new incident new form is opened and i will select this configuration item it is not setting it so there should be some mistake in our script let's take a look so i think that's that's that's this is how kind of is interesting because if you don't get the response you don't get the expected results then it will be really easy now you can just go for uh debugging so in this case i already found the issue you can see we have this incorrect name here assignment group so i will just save this i think i think this is kind of giving you the learning as well while if i'm doing the mistake you can understand that you have to make sure that while writing the script or before you perform the testing make sure you're checking your syntax if everything is written uh i think with correct syntax and the names are correct or not that's something you have to check before you perform the testing so um it's correct now let's see if if i do it again so i will reload it and i will select the same configuration item let's select it and if i select it it is not setting the value again that means there's still some some some kind of issue so if i go here get ci i think we have the set assignment group maybe let's check that set assignment group answer we have here set value okay so we have done mistake here as well populate group another mistake we have done so let me save this and that's okay it is kind of debugging you are doing not at the actual debugging but you are just checking your script whether it is it is uh it is working you have written all the all the words or names you have given right names or not not that is something you can check and now i am going to my form again i will reload it and you always need to reload that's how your updated script can action can take that action the latest action which you have just updated so i will uh just do this select it and if i select it it is still not setting it is not working so i come here again and the reason behind it you can see that because we have selected active field here you have to select configuration item i think it's good we are doing a mistake i think it's good at least you will not do those mistakes if i'm doing the mistakes so in that case i have selected this so you can see we have these i think everything should be good now i hope fingers crossed we should not get any error now and let's select let's select the configuration item and it is not working yet we still have this new value we have sperm ci get ci it is again another mistake we have done you have given a space because it's a string it will definitely take that space as well so i will reload we are doing a lot of mistakes i think so let's see i'm sure this time it should work if i have not done any kind of mistake yes at last we are able to populate assignment group the names which we have created that's something it's kind of wrong uh we have given so but but it is working you can see now it is populating id securities automatically so this is how you can achieve uh this kind of requirement if you will get this kind of requirement where you have to populate something on client and you can use glide ajax you can call server side code pull it on on the client and use that value on your client in this session we will learn about workflows and how you can do scripting in workflow this session will majorly focus on scripting in workflow as this is for developer training we will start with what is a workflow workflow is an automated sequence of activities it can run repetitively that means if you have some actions or steps which you want to run repetitively in that case workflow is supportive in that case in that scenario it performs activities as per the activity defined in sequence so if you need to automate a process you can do it with the help of workflow service catalog items are the best example where you mostly use workflows so if you have some steps maybe some kind of automation which you want to run in sequence maybe update off a field then creation of some task record sending an email in those cases you can use workflow which will automatically run each action in sequence and that's what workflow is baseline workflow service now has out of the box workflows which have been created for different functionalities like change service catalog or sla as you can see on the screen we have workflows for service catalog item request which is specifically for service catalog item then we have knowledge instance publish which is for knowledge management and we have some other workflows which have been created directly from servicenow and these are all out of the box however servicenow developers and administrators can create custom workflows as per the requirement from their customer and client workflow application and editor servicenow has a separate application to create and manage workflows here you can see the application called workflow which is the application where we have different modules to manage workflows as well now the major module the main module of this application is workflow editor which is the module which opens the editor for workflow where you can see existing workflow and you can also create new workflows or maybe you can edit existing workflows workflow editor components workflow editor interface has different components in service now the first section we have is canvas which is the main part of editor then at the top you have canvas tabs where multiple workflow can be opened in tabs then there's a title bar which shows the details about selected workflow as you can see it is showing the name of the workflow and it is also showing whether that particular workflow is published or not in the right hand side we have palette where you have list of workflows and activities and at the top you have parrot tabs where you can see two different tabs one is workflows which will show you the existing workflow and then the second tab basically shows you all the activities available for a workflow while you will create a new workflow or maybe open existing workflow workflow activities in order to process the automation you add different activities in workflow for example if condition running a script sending an email or ask for an approval activities are added and removed on workflow canvas for a workflow you can also define the transition between different activities in the workflow from start till end so these are the workflow activities the first workflow activity we have have is approval activities in which you have approval group approval user approval action and then we have condition activities where you have if conditions switch condition wait for condition that means if there's a condition is being met till then it will wait and then we have notifications in which we have create event activity and we also have notification which will send an email scripting in workflow developers can also perform scripting in workflow lot of activities have script field which gives ability to perform custom scripting and logic as per your business requirement so these are the activities where you can do scripting and the activities are approval user approval group if wait for condition activity notifications activity create event activity rest message activity run script these are just example there are other activities as well where you can do scripting and service now in workflow practical demo now in this section i will create workflow and i will try to add different activities which we talked about in workflow and that will happen practically in my personal developer instance so this is my personal developer instance where i will create a workflow and i will add different activities now in order to show you this demo we will just take the scenario of incident so what we will do we will create this workflow for incident table now as you know that we can create workflow in any table for any table you want as per your business requirement so in this case in this scenario we are going to create this workflow for incident table so what i will do before that i will just quickly show you the workflow application we have so if i type workflow over here so i can see this workflow application and i have this module workflow editor if i will click workflow editor as you know it will open workflow editor in new tab where i can see the list of workflows we have that are also published and we have checked out as well and here also we have list of workflows in one tab and then we have the score tab as well where you can see the activities now what i will do i will create a new workflow for that i have to click on this button new workflow now this session is basically related to scripting in workflow so i'm not going to talk much about workflow because you must have learned about workflows in your administration section or administration learning but this particular section is specifically for developers because this is part of developer training so how exactly you can do scripting in workflow that is what you are going to learn so in that case what i will do i will quickly create a workflow on incident table so here i will do maybe sas now uh youtube demo let's say i'm just giving a random name now you can definitely give a logical name i will select the table which will be incident this is selected i will go little bit bottom here it is asking me conditions for conditions i can give run the workflow always and i can click on submit once i will click on submit this will create the workflow but as of now workflow is not yet completed because we have to add different activities as per the requirement we have so what i will do you can see here we have begin and end this is something which gets created automatically when you create a new workflow and this is also showing you the transition but what i will do i will just delete this transition because we have to add different activities between begin and end activity so i will put it right here and now what i will do i will start with first activity that is if activity so if you will click on core tab you will see all the available activities which you can add here and just run the workflow so we will start with if so here we have in conditions you can see if our click here and i will drag it if you will drag it on your canvas it will open up the racket that means that activity racket and then you can create it so in that case maybe i will do check priority now what exactly we are doing here i am going to checking the priority of the incident created and that's how i will run the workflow so in this case what i will do i will maybe so now i'm going to tell you one thing that you can achieve or you can do or you can create workflows and you can add activities with the help of drag and drop option as well so here for example you can definitely select the priority field because as i mentioned the the requirement basically we have for priority so if the priority is p1 then only it should do is it should basically go for the next action else not and we will see what actions we are talking about so i can definitely select that field but it it might happen that you you don't have that particular field available maybe you can't access or maybe you have a complex logic in that case you cannot use directly this condition a condition section so in that case what you can do you have to write a script so as of now i'm not writing a complex script because in that case you won't be understand better because this is just a developer training so i just want to make sure that you are able to get it what exactly we are talking about so as of now i'm not putting that condition over here what i will do i will check this box advanced so once you will click on this advanced check box this will open this script field and here you can write the script which you exactly want to consider as a condition because you have to evaluate whether that particular that particular condition is is being met or not how exactly you can do that what exactly we need to do we have to check the priority if priority is one then follow one one way if we have the priority is not one it's not critical then it should just shouldn't do anything that's what we want so in that case what i will do i will type here so answer now this is the basically here you can see the example this one now this is the syntax off of your script so that's i think i would say it's a really great feature that servicenow is providing they are giving you the help that what kind of syntax you have to write here so that it can run so what exactly it is doing you have to basically uh push the answer um basically the value the the value of that particular uh basically uh condition whether it's being met or not that's something you can you have to push it and answer so what i can do i can just run this basically function i can call that function how will i do that i will do check i will do check priority semicolon i will go little bit bottom here and now i will create that function so we have function check priority we will create this and now i will do if current dot priority equal to equal to if it's one now the back end value for high the critical choice is one and if that's the case i will do return now that return yes or no will be in the string so i'm doing return yes else it will return no and that is also in the string and then i'm putting semi-colon what i will do now so our script is ready it is saying okay so this is the mistake we have done there should not be semicolon here so our script is ready now i will submit it when you will click on submit you will see the activity is created so i can just put it right here what i can do i can just add basically connect this begin with this one that means once workflow will be triggered it will directly go to this step first that means it will check the priority now once we have added this if answer is yes our answer is no then you can drive the whole workflow what we will do now we are going to add another activity and that will be in utilities we have run a script so i will add it here now what i will do if priority is critical one in that case we will set the value of category field maybe uh to software if it is something else maybe in query we will make it software now it is just a demo i'm just showing you so that you understand scripting so run script is basically basically it runs at server side first of all and it is kind of a free form of scripting so anything you want to run at server side you can definitely use this run script so what i will do i will put it here set category and you can provide the name as well so i will do set category now here i can do current dot category equal to now this is the choice value back-end value of software category and i can just current.category i can just click on submit that's it so i have written that script basically and it will automatically uh push that value now what exactly we can add now so let's add another activity that is approval so maybe it will set that particular value but we will also send it for approval so if you will send it for approval let's see let's see what exactly happens so what i will do i will add this approval user now where exactly we want to send this approval which user should you should approve it basically this this particular racket so what i can do now you you do have fields like uh caller or maybe you also have assignment group you also have a signing but maybe just an example uh you want if callers uh you want to send approver approval to the to the users who are from the same department of caller so whatever caller is being selected so approval should go to those users who have the same department now this is something you cannot select with drag and drop or this manual configuration this is not possible you can see that it's not possible because there are multiple rackets because i have to pick those rackets uh all those who have uh department as as uh same as caller uh caller uh feed so in that case what exactly you can do i will just mention set the approval as caller department users now what i will do i will check this advanced check box because that's how if you will click on this advanced check box then you will see the screen where you can write the script and it says additional approvers script so i'm not adding anything over here i am just mentioning the script here so here you can write the script it is also showing you the syntax what syntax you can use so what i can do i can quickly do here answer i think that's the same syntax so you cannot change it we will do answer equal to now you can see that it is basically making an empty array and you have to push the rackets into this array and that's how that particular approval will happen so what i will do we will basically glide racket because we have to check the department of the caller we have on this incident racket and then we have to glide record all those users who have same department so i'm sure we have to do this glide racket so i will do where gr equal to new glide racket and here i can put the table name that is says underscore user semicolon here i can do gr dot add query and i can do department now department is the field name on user table because we have to check the department and i can just do comma and now here i can put let's say current dot color underscore id that's a field we are capturing the user data which is in the caller field so i got the society but now you i have to dot walk it and i have to get the department of the caller id and i can just do it with the help of dot work that is dot department semicolon and here i can do gr dot query and i can do like this now i can do while because it has to run the loop because you might get multiple users with the same department so you have to run the loop and then i can do gr dot next and then i can write the script over here now here i have to add semicolon now what exactly value you have to push now we have to basically push it like this answer dot push and here you have to push the society of that user now i can definitely get that society with the help of like this gr dot says underscore id if i will do this it will definitely return me the society of the user which is coming in the loop but there are multiple users because you might have multiple users in that department how can we push multiple users so that it goes for approval to all the users in that case what you can do let's create another variable here i will do where a maybe just a random variable and i will make it blank now here what i can do a equal to i can do a plus now how you have to push this value in the array that's something we have to do with comma so i will do this comma and then i will do this plus we are pushing society i have this answer dot push and now i can just do this a so what exactly this a will capture i can tell you right away so i will put it as a comment so that i don't want to run that code if you will do that this a equal to will be i will quickly show you what exactly it will capture it will be like for example you have multiple society now this is a society one society and then you have another society that's what it will push because it is keep on capturing that gr.society that means the user id user society um basically for each user you have so in that case you will able to capture in the a and i will just delete it for now and we will do this answer dot push a and i am going to submit it so it is submitted you can see we have this approval user and now what exactly this approval for why we are doing this approval so and i will make this note to end and we will we will make this yes to run script so that it can update the category which we just mentioned over here and then what i will do and i will also added this transition so we'll make this transition over here a little bit down here and let's say this one here and like this so now it will ask for approval to all these users now if i open this approval user quickly so what we will do as part of the getting the approval so we will just make it wait for anyone to approve and we will make it when anyone rejects so it will reject the approval that means it won't be it won't be approved so in that case it will follow these two paths approved or rejected now where what exactly action you want to take once once these are approved or once these are rejected so in that case what i will do i will maybe add another script here run script let me add that one because we will write a script here and what we will do we will set the description this time so if set description so if it is approved i will do current dot description equal to now our description will be mem ticket but that's a p1 ticket so let's say make it major incident management ticket mem ticket and we will add as a prefix with the current description we have so we will make it current dot description uh we will do like this current dot description mem ticket plus current dot description that's it i will click on submit so you have created this script now this is for approval so i will just add it here now what about rejection so if somebody basically rejected rejects this particular approval what exactly you want to do what we want to do we want to basically uh change the category let's say so you have if you have uh the category then then we can just change the category in that case so what i will do i will but how would you come to know that what was the previous category so what you can use now here and that's called you i think if you have learnt about scratch pad so now i'm going to use a scratch pad here because i want to store the previous value which we had for category because here we are changing it so how i will come to know in this step this category should not be changed it should be changed the previous value but i don't know the value right now because that has already been updated so in that case now i will remove this one here i will write another run script and i will capture that value so i will make it like uh capture category so i will just capture the value of category how can you do that now when you create the scratchpad for workflow scratchpad basically it's kind of a placeholder where you can basically store that value so that value will be stored during this workflow so what i can do i can do workflow dot i can write scratch pad dot here you put any variable you want so maybe i can put short d and now i can what value i have to store current category so i can do current dot category so here i have mentioned like this i will just copy this one because i have to use it in the another activity now this particular activity will just store the value and then it will go to the next step so i will go here now if it is rejected so i will add another run script here now i will use that particular value which have been stored in scratchpad so i will mention here set category and here i can do current dot category equal to this is i think we have used short d i don't know i think we have to make it as a category not short d maybe i can just do cat for now so we have current dot category and this is workflow.scratchpad.cat now you will say it is not the same name so i will change it here quickly and i can make it cat and i can update it so it is done now i will make it rejected here and i will add it to the end i will connect this to the end that's it that means the category will be changed if it is not approved and if i validate it it is validated no warnings no errors i am closing this and now i am going to publish this and this time we will test this workflow so if i go to incident now so let me go to incident now what is the condition of triggering that workflow the condition uh for triggering that workflow is that priority should be one so in that case i will select any caller let's say this one apple tutor and i will keep this category in query as it is i'm not going to change it and i will make it high and i will make it like this and i will do test short description and i can also do here test description and if i save this let's see what happens it is saving the record and you can see that it has set the category value to software but it has definitely send it for approval as well so if i go a little bit bottom so i don't have any approval related list but if it it should have sent that approval for sure so how can i know that i can just maybe add a related list approvers related list so that i can see it so i have this approvers i will click on save and if i go little bit bottom you can see that we have 32 approvers how it took the approver so what i will do i will quickly show you so that you understand how exactly it is picking up the approvers you can see we have 674 rockets but out of 674 it only selected 30 uh two or 34 records so i will just quickly drag the department here is the department so department for able tutor was product manager and if i do show matching so you can see we have 32 rackets that means this approval was sent to all these users now if i go to that incident again so i have this test short description over here and if i let's say i approve this now if i approve this so description should be updated so let's say i'm approving this i'm an admin right now so i can definitely approve it directly from this screen you can see that here it has added mim ticket as a prefix and then it is showing the description which was earlier but that's how your workflow works and you can do scripting but now we will see the rejection as well so in that case i will create another ticket and here i will do test short description and i will do test description and i can just select the same one so that it can select the department accordingly i will make it critical and i'm going to save it if i'm saving it you will see that category will be changed and we have short description description and if i go at the bottom you still have those approvers this time i'm going to reject it if i click on reject you will see difference you will see that we have back to our same category which we had earlier in and help so that's how you can use the power of workflow now this is just a demo as part of the example for this developer training but workflow has really great power so that you can utilize you can automate a lot of things a lot of process a lot of i would say even if you want to do some automation work that's something you can achieve with the help of workflow now before i end this video i also want to highlight one important part that servicenow has also a great feature that feature is flow that comes with the flow designer so similarly like you create workflow you can also create flows as well but the only difference is you will need less scripting over there so whatever we created this time over here you can achieve this with the help of flow as well and that is also provi uh that is also without scripting i will try to do one thing i will try to maybe publish another session with the flow without doing any kind of scripting so i hope you like this session the whole training we have for developer training please provide any feedback please post any comment like share my videos as well and subscribe to my channel thank you and have a great day