logo

NJP

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

Import · Dec 05, 2022 · video

foreign [Music] and this is the second day for that okay so uh if you have not seen the previous video please go and watch it okay and as you can see on my screen okay so we have added a couple of error messages couple of information and so on as a part of the previous video so just go and check out because this video will be on top of that video okay so we will start exploring your other functions of the right form apis okay and let's get started so the first first function which we want to see today is clear message okay so what this clear message before that let me create one uh one script Okay so I'll go with okay I will I will I will go with the second tab okay I will do configure client script voice client script and we will create one more client script on top of the previous one so the previous one multiplied form will create the client form too I'll create form to and we will make it on change this time okay so we'll do it on change and on change of what so let's make it on change of category field okay and I will see this sound okay it's a draft so we have created this script out okay and now let's move on with the first function so the first function in our left is the first function on our list is clear messages okay so the what this particular function does so this particular function removes all the information in error message from the form okay so you can see there are tons of messages okay which are there on the form now using this particular method we can't remove those out how let's look into that so I'll go over here okay and it's change of category okay so we will go here and we will do key underscore form Dot clear messages it doesn't ask for any argument okay because it doesn't need one right so what it does it just clear out the message okay from this from the form so save it out will go here and we will reload so ideally it should vanish all the messages which are there and the form okay let's see it got loaded but nothing happened okay why nothing happened clear messages reload the form again oh why it didn't happen because it's on the change of categories sorry my bad so we have error messages and information now I will change the category to software and boom all the messages are gone okay this is what this particular function does the next method in our list is clear option so what this particular function does we have to pass a field name inside that and what it does it removes all the choices from all the choice option from that for that particular field so and it worked only on Choice fit right because we have option for Choice field only so for example let's what to scroll up okay let's look at the channel okay and it has couple of choice but now we want to vanish it out uh you can consider it in a scenario where uh you don't want to provide a choice based on certain criteria that if a user is having minimal Road right why you want to give them that choice to change the state so you can clear the state option I'm just thinking out loud right about the use case so how you can Implement that so we will be removing from here so it's contact type okay I get the name so that we can vanish it out for this contact type we'll go over here and the same context okay I will just zoom out a little bit it's G underscript form Dot clear options and is ask for which particular field you want to clear the options for so you can simply provide a string input which is contact type and save it out so if I go back over here and if I reload the form right reload reload reload leave So currently you can see channel has couple of things underneath it okay and also we have the several messages bothering us out now if I change the category to Software let's see what happens now the message is gone as well as the choices are gone for the channel isn't it amazing I really like it okay so this is second method in our list today let's move on to the third method which is clear values so what this particular function does it removes any value for from the field for example you want to make this blank short description you want to remove description or any other field on the form it doesn't matter what field type it is so you can use this particular function out okay so for example if if you ask me an example which is coming on top of my mind for example if there is a user okay which has a role called bad guys okay which just want to screw the system we just want to create unwanted incident so whenever they create an incident okay uh if there is a if they are applying template okay you can simply remove clear the description short description value so that they have to provide what exactly they are trying to do okay so let's move and we will remove it from description let's clear the description so I will go on show just get the name for that okay description copy I'll go over here and I will do G and just confirm Dot clear value so we are covering all the clear things right and clear from what so it's description right pretty easy to implement right I will save it out and I will load the form so you load the form leave so now the description is filled right okay now I'll change the category to Software okay and now you can see the description got vanished right this is what that particular function does now moving on to the next method which is disable attachment so uh consider your skill for some group members you want to disable the attachments you don't want them to provide an attachment right okay so you can disable it out easily on the client side using this particular function okay which is called disabled attachments so how to implement this so as you can see currently you cannotize the internet attachments right if you click on this choose file and you can choose anything okay for example let's take my take a mark and the attachment is getting attached to this particular record but now if you want to disable this particular thing then you can use that particular function out so it already got attached so I will go over here and the Syntax for that is like it doesn't ask any attributes okay arguments are not attributes so form Dot this able attachments pretty easy pretty handy and we can do the sieve so if the and you can Define all kind of conditions right that if category software you don't want attachment and all those things out okay so I will reload the form again whenever you are doing anything whenever you are adding anything on the client side just reload the form because that's where it starts reflecting as you will bang your head why it's not visible for me and you will not get the answer so now let's try to change the category to Hardware and now you can see that particular icon got vanished right so you want to have a category like if and now if I do there is another function now you will be asking okay we disabled the time how we can enable the attachment right so for that we have a function called enable attachment okay so consider cutting uh consider a validation that if category I will do the the whenever we change it out okay now it's it's not visible right okay for example if I do if I want on um so if I do this if G underscore form dot get value of category is so we just want to hide it for uh for what you can say software okay so I will just look at the Choice value for this okay so I'll show choices leave and if the category is software okay then only we want to disable it out as we want to enable it out okay so you can do like this if the category is software then I want to make disable okay yeah underscore form Dot disabilitation I want to disable it out else I want to enable it out I can go g and description form Dot enable attachment so only for software when we change it to the software it should get disabled okay it's mixed up tabs so I will just align it out I'll save it out now and now if I reload the form okay okay if I reload the form so we have attachment enabled right now okay okay why okay because we are not changing anything so if I change this to Software I I think I messed up something if category is software category is software then disable attachment else enable attachment I changed to software right what is the backend value so I will go for show choices again oh my gosh and value is software only right oh showing inactive is there any other software oh for incident I will do show matching for incident so we have software small keep this in mind okay whenever you do configure choices it will show you choices from all the table which extend task table don't make mistake which I did okay okay so I'll go back back and we will will reload the form just to be sure now if I change it to uh now if I change this category to software it should disable this particular icon if I change the category to Software it got vanished now if I want to re-enable it out I will change it to something else for example hardware and it came up pretty amazing right and the last method in today's session is Flash it's not that Marvel Flash or sorry DC Flash uh for this flash match it does okay so the flash method is used to draw attention to that particular to a particular field okay now you can Flash a field out okay so that uh a person will grab an attention when he opens up the form for example in our case we give we want to flash caller ID because that's the most important so what is the Syntax for that so that the Syntax for the C image it's let's add to the software only whenever it got changed to software so what you have to do in the underscript form Dot slash so you have to go Flash okay and this particular function asks for three attributes okay one is the field name so we'll give caller ID underscore sorry character id the second argument which is asked for is a hex code okay for the color which you want to have flash off okay so I have a hex code for the same okay I'll just build that fax code and the last attribute is for how much duration you want that particular thing out okay so it's a numeric field okay a count okay which specify how long the label will flash okay and it is you should you can't give 1600 seconds and all those kind of things it has couple of options okay with it so if you give two it flashes for one second if you give zero it flashes for two seconds if you give minus two it flashes for three seconds if you give minus four it flashes for four seconds okay it's quite weird okay but let's go and try it out for zero okay and I will save it out let's so saved go back to incident reload the form as always leave okay and now if I change it out to what we can say category to Software right you can see it was flashing right right let's do it once again let's because it's removing the Focus right let's remove the description thing so if I reload the form now and if I change it out okay to software so you can see the flash is happening on the call of it right okay so this is all for today's tutorial hope you like it out okay please like follow subscribe to my channel to get the latest notification of the upcoming videos okay till then stay safe stay happy and to participate in this service now JavaScript challenge okay I'm learning a lot out of it okay so then thank you and have a nice day at it

View original source

https://www.youtube.com/watch?v=78AGvFbuNsA