logo

NJP

Servicenow Form Section Hide / Show | Servicenow form section | Servicenow Client script | Snow tips

Import · Jan 20, 2022 · video

[Music] hi all and welcome back so today's tutorial will be one of the scenario-based uh tutorials okay in tutor and i will start concentrating on the basic tutorials also because i'm getting a lot of comments from people that they have just started with service now and they want to know the basics also okay so i will try to cover some basic tutorials also so in today's tutorial i got one of uh one comment from one of my subscriber and they asked me how to hide and show the form view uh form section okay so today we will creating a tutorial on the same okay so let's get started you can see on my screen of the interface for my servicenow instance okay and for today's tutorial we will go to the incident table only okay let's go to the incident table uh let's let me go to all incidents and first of all i will try to explain you what our form sections and then we will will proceed with how we can show hide based on the criteria and all that things so this is a incident form okay as you can see on the screen i will just zoom out somewhat okay this is a incident form okay and what you can see on the incident form this nodes related records recorder information these are the sections okay on this particular form now for example let's say we have a requirement that when uh we have an incident of type of priority critical then only we want to show related records as you don't want to show the related records so how we can achieve this so into this review we will be focusing on that so first of all in order to get to do anything on this form right you have to first understand what is the backend name of this section right okay so how you can get that so and the second thing is like what exactly what approach will you will you follow okay in order to achieve this so as this is on the client uh client side okay so we have to we have to follow the client side sector only okay and in that you can do it via client script because you have the provision to write a script over there and you can simply easily do that so let's go to the scripting part so first of all i will do what i will do i will just duplicate this tab out okay i think this particular is closed let's open some incident which is open so that we can use the same incident okay so let's open this incident i will duplicate this tab out okay so that we can write a client script on top of it okay now you can right click on the context menu okay configure under configure you can go to the client script okay now what type of client script you will write that was this next question okay which is coming in your mind so as you know there are three types of client script four types of client script basically okay on change on submit on sell edit and uh fourth one is on load okay so yeah you have to think in this way you don't need a onload kind script right okay you want an on the change of the priority field okay so we will be writing an on-chain client script so i will create a new client script i'll give it a name on on change okay unchanged i give the name in this way okay this is my naming convention okay because it it helps me out to understand okay uh what exactly is this what type of client script it is okay and on what particular field it's it's acting upon so it's pretty easy to understand but you can have your own way of working right so now we will go table is incident it's auto selected ui type you can select either desktop mobile service button or all currently i'm working on desktop so i will select desktop now on the type you have to select on change as soon as you select the on change you have to define the field on which change of which field you want to execute this client script so we have to do it on the change of priority right okay then we have application i will keep it in global application active active inherit inherit what it does if you check this check box inherit okay then all the child table okay which is extended from instant table it get inherited on those tables but for now we don't want that okay you can give the description okay it's i prefer giving a description because it helps us out okay in the future so we will be giving incentive right hide form section when um when student is off you can give something okay i'm just giving it uh making some grammar mistakes also okay so that's that's how now you come to the scripting part okay so as it's on change you have a control to control okay on or old value new value is loading is template okay so first thing first and the foremost thing what is the criteria which you want to define okay it's like whenever the incident is critical then only we want to show related records section okay so first of all that means we have to hide it out right okay so let's we will hide it out in the is loading itself so when it get loaded at that time only we will hide it out and then on change will work and it will execute or no need to do that also okay uh we will write a different on load client script that we can you can figure it on on your own you have to just copy paste the script which i'm i will be writing in the client script okay now what you have to do is first of all you you want to get the section name right because you do you can't simply configure right click configure and see the field name the way we see the field name right for the form section okay so there are two ways to do that the first way is like you can simply search for form section okay so you can open the form sections okay and in the form section you can search for table which is incident okay on incident table you have to check the views where is the views on which view so currently we are in the default view so we'll go to show matching to the default view and now you you get this and we can go for true one okay so now you can see there are four sections okay sorry just i made a mistake you can simply do show matching on incident okay and now you can see the four section notes related record resolution and this is empty section okay so you get notes related record resolution information okay now if you go if you want to write a client script okay so what you can do this is the first way to get the name okay the second way i will be showing why script okay so you can simply do variable sections equal to g underscore form dot get section names so what it will do in this gate section name will uh will look into the current form okay and it will retrieve with the array of sections i section them okay and we will be doing alert okay just to get the name okay just to get the name and it goes it comes into the order itself so we want to hide which first second third third the third one we want to second one we want to add right so we'll be looking what is the name for the second one okay so i will simply go and save it out okay and now if we go to the incident form if we reload the form okay every time whenever you write anything on client script you just reload the form out okay and currently the priority is low okay i will just change the variety and it will get executed so you can see now as soon as the priority get changed it give the term it gives the alert message so the first section name is notes second one is related record and the third one is resolution information so i will just copy this related record once okay because i want to hide this only okay so now once we get that thing out okay now the next thing what we have to do is like we want to write this logic around this so what our logic is i will just give on hide section just for my reference purpose now what we want to do is we want to understand when the priority is critical then only we want to hide that section out right then only we want to show that section or you can see okay so what i will do i or let's make that way when the priority is critical then we want to hide that section because it's critical incident right okay so what you have to do you have to just you have to just check for the choices right i don't know the choice value for what the choice is so you can go for show choice list leave okay we will go for incident i think it's coming from task table order yes it's coming from the task table so task symbol critical is one the value is one okay if you are not getting on incident form that means it's defined on the parent table itself that's how i guessed it out okay now what you have to do you can simply uh comment this out also because we got the section name right and now you can write the logic that if g underscore form dot get value value of what we want to get the value of priority okay so i will give value of priority is equal to what 1 okay then we want to hide that section okay so we will do g underscore form okay i'm just creating it for demo purpose don't take it intentionally okay that white on critical i'm just um hiding the resolution information related records right okay just for the name of purpose you can discuss form dot set section display okay now it will ask which section display you want to set okay so we can give section display this okay and what you have to do you have to set the display to false okay if the priority is critical and you can give the else condition also else you should give these as condition because if you are not giving else then it will stuck on that particular condition only okay um that means if you change to critical it's got set to it just hide that particular feed out but if you change it from critical to some other value it should show also right so for that you need to define this uh i will just copy paste this out paste and i will make it true for other sex segments okay what warning i'm getting make space control a shift tab okay save and now let's go to the incident form and let's see if it works one step back one step back okay i will reload the form ideally it's already reloaded because we came from a different page but yeah still so now currently the related records are visible right now according what we have implemented if we move it to critical then it should hide that particular section right so let's do that hi i'll make it this also high and now the priority change to critical okay as soon as the priority got changed to critical the related section got vanished okay now we are unable to see that related section related request section okay now if i change it back to any other value now it changed too high okay from critical to high now it showed up okay so this is how you can hide and show the form section okay based on any criteria okay you can have your own criteria and you can define the logic the way you can just change the condition alter the conditions out right okay this is all for today's tutorial hope you like this tutorial okay please drop your queries in the comments okay because i'm trying to create the videos out of your ideas only okay till then stay safe stay happy and have a nice day thank you

View original source

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