logo

NJP

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

Import · Dec 26, 2022 · video

foreign [Music] chapters okay so as we are following this service now JavaScript challenge okay so this particular challenge or this particular video will be covering the topic from I think uh page and five to eight okay so this will be the last on the platform API okay so if you have not seen our previous video please go and just get a reference out of it also so let's get started without wasting time so in today's tutorial as I already stated that we'll be exploring some interesting functions on Live Form API with the demo okay so let's go to our all-time favorite table incident again dot list okay okay and I'm not sure what kind of client script we have used for the last tutorial let's see okay so we'll be using only slidescript because in the last tutorial I used all subject line script for the demonstration and it took a really long time for us okay so let's get started and I will go over here to the United States configure client script foreign script we will give it a name and applied form five and it will be on change on change of anything I just want to demonstrate what the function does so we'll do non-change of category and boom we are ready to go so let's start with the first method and the first method in our set in our list is set field message okay so basically what now what this particular function does you can using this function you can add any message on the field okay so we have seen the banner messages like add information and error message in the similar way so show message will help us to show the message on the field itself okay pretty amazing okay so you can consider us you know you're like uh based on based on certain inputs for example description you want to give some information on description that what exactly needs to be added over there or you want to show some error fields or warning okay for example there is a string field where you want only capitals letters then you can give that message over that that this particular field should have only capital letters so it will help the user to add the relevant information over there or you can think of any use case in your projects so how you can the signature for this function is three undercut form Dot show Ed message okay and is asked for three attributes one is like the input string okay in the message uh on which particular field you want to show the message second will be the message and the third will be the type of whether it's Error Message or info message okay so let's add to the description uh so I'll give description and we want to give the message okay please provide valid description right and it should have a type as info because it's an information one right and let's let's copy the same okay and let's add one error message also okay so I will go over here and instead of description we will give it on caller ID and we will give request only okay okay I will give it error so let's save it out and see how effective looks on the form so I will re refresh the form reload the form um and we have changed it we have made it on change of category right so if I change the category to software okay so you can see this is the error message and this is the information message this is how it looks okay now you have added the machine now you want to remove it out right so how you can remove that message out okay so for that there is a function called hide all field messages okay so it will be the Syntax for that is clear liquid form for DOT height read message read messages okay so there are two things one is a hide field message as you can see on the screen which will hide everything okay and the second one is like uh hide hide the message okay on the particular particular type of message so we'll go for the hard messages and on which particular field we want to so we will remove the message from description okay done and receive and if I go back to the incident form if I go back to the incident form I've reload it out leave and if I change the category now to software okay remove the message okay oh once the message is there it can remove that message so just keep this in mind okay we have this particular function okay then next in our list is um I think I made a mess over here okay yeah so this is all for this three these two functions okay the next thing I'll list is height related list so as you must be knowing what is related list so you must be knowing this whatever you see at the bottom right these are the related list and you can see the related list name also what exactly the related name list name is so if you can you can see that this has the name task SLA this has CI and so on okay so you can hide certain relatively based on you know based on certain criteria right so for example I want to hide uh tasks CMD Services when the category is software okay oh or when the category changes okay foreign so what you can do is chain description form Dot height related list okay and you can provide the list the which particular list you want to hide I'll just remove the space from here so you can consider scenario for example if if there is certain entity or for example I'm thinking out loud okay that uh you have a caller okay for that particular caller you don't want to showcase in the SL information so you can hide the particular list when that user with that particular role is okay or any this kind of activity so I will save this out and if I go back to the form so we are removing this one okay reload leave okay and it's still there it's still there it's still there now if I change the category to Software if I go down so you can see the related list got revoked or removed okay now you will be asking okay we have removed it now what if we we want to do height show okay so for that we have a function called Shear description form Dot show deleted list okay which just does opposite of this okay so you can simply pass this cmbcl services and boom it it will it will showcase it back so this is all done okay now the next method in the list is what The Nest is mandatory okay is mandatory so you know there are a couple of fields which can be mandatory on the form right for example is there anything mandatory color is mandatory so this particular function will help you get the information whether that particular field is mandatory or not on the form okay so I can give alert and we will check if that particular field is mandatory or not so G undercut form Dot is mandatory okay and then you can give caller underscore ID so if it's mandatory then it will give true as it will give false so I can give some context for this is caller ID mandatory so we'll get some more information and I will just save this out and let's see how exactly it works I'll go tab okay I'll reload the form okay and now if I change this out to software so it gives caller ID it is mandatory why it's giving false yeah it's giving Boolean value but why it's giving cause not sure right did I add negation to this no oh oh there is no field called call or ID okay so it's caller ID okay I made a mistake I will go back I will reload the form leave and now if I go and select software so it shows it's called identity yes true because it's mandatory okay so you can play around the same okay uh that you can oh how I use this field is like I used to check couple of fields basically those are those fields are mandatory or not it's mandatory so you can create an array of the field which you want to have a watch list on okay then you can check whether this particular field is mandatory on the form based on whatever condition is there on the form if it's mandatory okay if any of the magnitude field is missing then you can give some error message just thinking out loud okay now the next message method in our list is is new record so whenever we have we create a new record okay if you want to see whether it's a new record or it's an existing record we are trying to update so this particular function is quite useful so for that I will just comment this out for a second and and I will add alert and you know new record colon space and you have Plus G underscore form Dot is new record so what it will do it will give a Boolean value based on this particular record is already existing record or a new record okay so I will save this out and first we will try with the existing record okay so I will go over here and let's reload the form and if I go and change the category okay to Software okay is new record no it's not a News Record false okay it gives us false now if I go over here and if I do incident dot two just to have a draft of a new record and let's see what happens over there okay brand dot two leave okay now if I change the category over here then it should show okay it's a new record now okay so if I change it to software now so is the new record true yeah it's a new record okay so this is all about this particular edit moving on to the next method right uh so the next method is now we have seen how we can hide and show the oh get rid list right but on the form if I go here and if I open this instead in the previous incident right if I open the inside there's something called as sections also in the form so you can see this section notes related records resolution information all these are section if once based on certain Condition You Want To Hide certain section out for example you don't want someone to prod work notes and all these things so you can simply hide the node sections out right so you you can do it by one function okay and we'll be looking at that function so for example if you want to remove the nodes section so you can see that how what is the backend name for node function okay if you right click configure okay go to form layout and look at the sections so we will be hiding the node section for now so if I go over here and I will first of all comment this out and if I go g underscore Dot height section or let's let's uh let's before removing hiding the section we can hide the section the way is the same way let's look at one more method is section visible okay so what this particular function does is like it gives a Boolean value if the section is visible on the form or not okay so we will be passing a function called nodes a section called node and as that particular section is visible on the form right then it should give true right so I will just copy it out because we want to add alert for the same so I will go I will add alert what happened alert and oh I screw everything on that and in alert we can a node section everything but taste taste test and we can give Plus e underscore form dot is section visible and we have to pass the section for which we are looking for so it denotes okay and and see if now a lot of people will be like okay how will come to know the notes if you don't want to go to the section and all this thing okay so we have seen in the previous tutorial there was a function called get Section names right okay so you can use that function you will get a list of sections and then you can easily find out what what is that function in section is okay so I'll reload the form and if I if I go for category and if I select software right so is node section visible true why true because it's visible on the form okay in this way this particular function can help you out now the next question in our the next function in our list is set mandatory okay so as you can see this particular color field is mandatory if I remove this out it start giving me error right it's mandatory over here okay so how we can set certain field as mandatory let's go for description only so if I want to make description mandatory so how I can do so first of all I will comment this out and and I'll be like G underscore form dot set mandatory and it asks for two things okay oh which particular uh which particularly we want to make as mandatory or normality and then the second attribution is at the second attribute which we want to pass is Boolean whether it's true or false if it's true then it will make it mandatory if it's false then it will remove the mandatory okay so we will add description and if I go and I will make it true because it's already false right and if I if I save this out if I go over here and reload the form leave So currently it's not mandatory right if I change the category now I make it software now it turned out to be mandatory perfect right in the similar way we have one more function called set read only so the way you made the things mandatory right in the similar way you can make this field things read only also right so the function for which is used for that is set you must be you must have guessed it out right set read only say if I go to the read-only function I've passed the field name as description the Boolean value is true okay and I will simply save it out again [Music] go over here you must have seen couple of this function but couple of this function are new to me also and probably it will be for you also so now the description is editable we have removed the monetary conditions also okay now if I go and make it software okay now you can see it it turned out great only I can't type anything right so this is one of the useful function the next function in our list is State label okay so there is a possibility for for for certain things for certain Fields okay based on based on the criteria we want to change the label okay so for that you can use set label off function okay so for example for description I want I don't like the description for certain user or certain user doesn't understand the description thing or you can consider scenario you have given a description but certain people doesn't understand so you can use the language API to convert it to the regional language and then queue it as a label so you can do that so you can see share the script form Dot set label off and it asks for two things one is the street field name for which the label needs to be changed and the second is the label so I will again give this question and I will like I'll make it as summary if I go if I save this out we will go Ctrl tab reload the form leave okay and currently is description if I change the category now if I change it to Software so you can see the label got changed to summary isn't it amazing yeah and the last last two in our list and I really find it I'm really fond of it okay I didn't find the use case to implement the same but yeah it's pretty fascinating for example if you want if you don't want the user to click on the save or submit okay and you just want based on certain action you should get auto save kind of thing then you can use the function called CMG underscore form dot save okay let's let's set the description also so I will go the underscore form dot set value or description okay so that you will come to know the difference okay and it will provide description and will set the value as a very chord change so is it okay something like this okay now if I save this out right if I save this out and now you see the file so for example if you have a user okay who is using this form and you have said some default category like for example what is the inquiry and health and if someone tries to changes the software okay we are software then you would simply without taking his permission you just say update description and save the record out okay so this is the this is the same method in the similar way if you want to up submit the form then you have a method called form dot submit submit okay what it will what is the difference seven will stay on the same page while submit will redirect you to the list View okay so these are all the important functions okay which you can see in the light form apis okay I was not aware that we have this much of method because I am prominently using couple of thems only okay and I think this was the end of this Glide form series okay I will continue working on the challenge service knows JavaScript challenge okay let's see what comes further till then stay safe stay happy stay learning and have a nice day ahead thank you

View original source

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