logo

NJP

ServiceNow introduction to GlideForm API | ServiceNow Client scripts | ServiceNow JavaScripts - 1

Import · Nov 21, 2022 · video

[Music] hi all and welcome back so a lot of you must be participating in the service now JavaScript challenge okay which was initiated by Google only and I have one of the participants out of it okay of it okay and I'm learning a lot of things from that okay so I thought instead of just submitting screenshot okay let us create video of what all the learning I'm getting out of it okay so we'll go with the first day challenge the first day challenge is for the Glide form API so we'll explore some of the methods which are there in the third form API and probably in the next challenge we will look into the other remaining ones okay so let's first try to understand what is the client form okay EPA okay the Glide form API provides methods to customize form okay so this method works on a client side okay uh and you can use to decorate the things to do some validations or to add some error messages and kind of stuff so we'll explore couple of functions okay today as a part of this tutorial so the main function which will be looking for today is like a decoration function add error message add information search add options and add form message okay pretty basic we'll start with pretty basic things okay so let's get started as you can see my on my screen this is my personal development instance okay so and whenever we want to do some trials whenever we want to play around something okay what we choose we'll choose our favorite our favorite all-time favorite which is incident table okay so let's get started so I will click on all we'll go to the incident and we'll start looking into function each at time okay so I will just go to the open incidents okay okay at the first function in our list is our decoration so what exactly the art decoration function does okay so I'll just create yeah I will just pick anyone new okay and yeah we'll play around this okay around this only so let's duplicate this tab for the same so I will duplicate it out and we'll create a client script for the same so what our decoration function does add decoration function add the icon on a field label okay so basically you can decorate something out right okay so but you have to you have to keep something in mind first thing is like this particular function is not supported on service catalog it is part right okay second thing is like you should always avoid using twice the same icon on the form because it can break other things out right so let's let's see how exactly this function works so I will go and as this all these are client set functions okay so let's create a new client script for the same and we will call it what we should call it okay platform so I will name it as mm-hmm stock unlimited Glide what's happening with our system Clyde for and we'll make it on desktop okay type equal to we'll make it on load for now okay because it's easy okay so let's look into the first function the first function is ADD decoration I have already explained what exactly it does so you must be seeing whenever we are picking up some user who is VIP okay so we get an icon in front of it it's stating that it's a VIP user right so in the similar way we can do certain things out so for example on color uh on color feed we want to add some decoration to give it start start again so there are multiple icons already out of the box present it's icon power start I can start I can start empty and a lot a lot of things okay so what we'll be doing the Syntax for this function okay it's it's pretty easy so it's G underscot form that's the only thing which works on client side so you should and we have ADD decorations okay it has two functions one no it has one function sorry two functions one uh with three arguments and the second one is with four argument arguments so we'll go with the four arguments only so that we can cover the three arguments and four arguments both so the first argument which it causes like for which particular field you want to add the decoration for so for us it will be like this particular field what this particular field called its caller ID right so the the field on which we want to add decoration is caller ID so I will give caller ID over here the second argument which it asks for is what icon you want to add okay so there are tons of icons okay as I mentioned already present and you can refer some service not talks for the same okay so I will be using a star icon so I it's icon dasta then the name the third thing it's it's us was like okay you have given that you want to show this icon but what exactly this icon means okay do you want to explain it yes I want to explain it all and I can give it it uh let's icon okay and the fourth and the last thing okay which is if you if you just give this many attributes that's also fine but if you want to give color also okay to the string okay that I want to provide some CSS also so you can give it pro by providing such a string out okay so for example if I give color green that's it and you are done with the code okay if I save it out now let's see how exactly it works so it got saved okay we'll go over here and as it's a client-side thing right we have to reload the form so let's reload the form okay we have reload the form and now you can see because the star icon okay in front of it and as it got specified color also which is green okay and if you hover on the same it gives oh star icon so whatever you have provided as a third argument will be the text which you can see when you hover over the same let's move without wasting time let's move on the next function the next function in our list is ADD error message very important and I'm using a lot okay so whenever you want to showcase certain error message on your form okay you can use this particular function so it's the undiscript form dot add error message okay and you can give whatever you want to give okay okay um for example this is a fake user I'm not but you can give a message so basically error your message is very important when you are doing some validation on client-side or server side and you want to throw you encounter certain errors and you want to show it on the form to the users right so this function is really really important in that aspect so we'll save it out again okay and see let's see how it works and it's not only on on load okay you can use it anywhere so I will simply go over here reload the form again and let's see how exactly so you can see the red color okay it's always represent error so this is an error message okay it's a fake user in the similar way we whenever it's come uh wherever we have error we have in false right negative positive kind of things right so if you want to give some some information message okay for example some guidelines okay so you can use information message so if you could you understand form Dot add info message okay now you can give okay please click save to submit so far this is kind of information right if if people you are dealing with are that level of stupid okay then you have to give this so if I save this out okay then you can see the difference between uh info and error message okay so I will reload the form again and now as you can see please click save to submit the form okay this is the information so this is a difference whenever something is going wrong you can give error message whenever everything is right but you want to give some additional information you can go with the info message okay now there there is a possibility right that for example I will give you a scenario uh that you are doing a Glide Ajax right okay and validating certain users for certain roles okay and there's a possibility that that user is a bad user or that user is not a valid user now you can't Define that if add error message if this particular user is fake and add info message if it if if is the right user right it's not a best practice right so in order to make this happen on runtime okay we have a function which can act like a error message as information as well as a warning message and the name of the function is I will just uh it's like C and descriptive form Dot add form message okay it's not there over here but it's there on the list okay form message so how we will differentiate it out okay so uh I will give if I want to give info message so I will get this is an info message okay and as a part of second argument okay you can pass whether it's an error info or warning so it it was three values three possibilities either it will be error either it will be info or it will be one in mid in between Azure and info so we'll give first as oh info okay and I will just I'm pretty lazy so I will just copy this stuff out okay copy I will paste two times okay so this is error message okay I will give it as error and the third one you get so that you can see the difference right warning and we can give it as warning message okay Ctrl a shift tab and manage the indentation save and let's see the difference how exactly these things look so I will go over here I will reload the form reload the form and now you should be able to see five messages to from the start and now is that volume oh worry message also came okay so this is an info message which you can see in blue is info if you want to showcase something as an informational thing so you can use information there's a warning message whenever something is wrong for example a user is not a valid user who is acting upon this request then you can give this error message and the morning message you like it's not a blocker but it's a warning right so you better understand what exactly it means okay so these are the three things which you can give so what I used to do when I'm working right so whenever I'm working on scripting cloud and I'm not pretty sure whether it will be information error message of only message so in the Glide Ajax object with the message I used to pass we have to convert it into the string right Json into string I used to pass as a second argument uh like message and it I used to pass whether it's info error warning and I used to use as a parametric thing the second argument so it will check on the run time and it will see whether it's in error info warning message but you can find your own use case the next message the next function in our list today is ADD options okay pretty fascinating but I didn't get a chance where I used it to that extent okay so what and option does okay so it adds option to the choice list so it works on a choice this and it just adds option to the choice list okay so for example there are channels okay I also have my YouTube channel right but YouTube is not an option over here so you can do add G underscript form okay Dot what's that oh add option right option okay and if you can see it asks for three things okay one is like which particular field you want to add option four the second attribute is like what should be the backend value for that and the third is like how exactly what should be the label for it okay so three things are required okay let's look because I am not aware What that particular field called so I will go over here I will see I use SN util cheat sheet if it doesn't always need to use it's contact type okay so we will go over here and we'll get the files faded contact and that's good type what exactly this field does okay oh sorry what exactly we want to add to it so I will give a backend value as YouTube YouTube and what should be the front-end value for it okay so I will give CAP CO2 there's one more argument which is like where exactly you want to place it out okay so I want to place it out at number three okay and I can save this out okay so let's see if the YouTube gets added over there so I saved it out and if I go to the incident I reload the form reload reload reload reload the form and if I go to the channels right now oh so many messages sorry for that if I go now you can see the YouTube at the third number in my list say the index okay so this is all for today's video okay today we have seen some basic functions okay and the Glide form API okay hope it will be helpful for you and we will continue with this Challenge and I will be creating more videos okay on the same till then stay safe stay happy and have a nice day ahead thank you foreign

View original source

https://www.youtube.com/watch?v=gAe6i8Tyvro