Boost Efficiency with ServiceNow Script Action: The Ultimate Guide
[Music] hello everyone welcome back to our channel so today we have an exciting topic to discuss which is regarding servicenow description if you are curious about how to enhance your server-side scripting capabilities in service now you are at the right place right now so let's dive into it before we jump into script action because a lot of people ask me is a basic question so I will I have decided with every video I'll be clearing the basics of service now also so let's quickly recap what server-side scripting is in service now server search scripting allows you to write custom script that runs on the server server now server rather than on the client browser this provides a secure and efficient way to automate process and build complex functionality within service 9 instead now let's discuss about script action so script actions are powerful feature in service now that enables you to trigger server-side script based on specific event it's specific event okay it's not a servicenow events meetups right it's the event we should trigger from servicenow instance right this event can be anything from a record Being created or updated to a logging being executed you can you can trigger event from anywhere okay and this particular script action which is defined for that particular event will get triggered so without wasting any time let's get started so as the entire description was talking about events right so we got one instance that event is the mandatory thing over here so let's create a event then so I will go here I will call create an I will go to the inventory history event rest is the place where we create events okay I will click on new let's create a event with a promotional name which is technomanc sometimes we have to do this right and we'll be writing it on the incident table for now I'm just creating a dummy use case but in a project you can Define on this case around the same right have clicked on table but it's taking some time let's see I think it's loading and now um come on okay and I will write the table name as incident y incident because it's our favorite table I think it's when it comes to the development side it's everyone's favorite table right but when we are working on a project right it's no one like this vertical table out right and whenever you're creating event right just Define the fired by condition and description okay it helps user to understand okay it has the developer to understand when he comes to the event at the lighter point of time from where he's getting fired and what exactly you'll be doing from this event so I will just give a smaller introduction hey I will trigger it from business and what it will trigger protection with name technoma okay and I will simply save it out now as we promised over here in the description in the fire by condition we have to create a business report right so you have this related list over here so from event you know you can trigger two things either script action or a notification so in this particular case we will be creating a business business rule to trigger that particular event and as I promised I will give this also a name as technomanc it's taking some time I'm seeing lag on service now instead from a couple of days not sure why so I will give it a name as technomanc I will go to the advanced condition will give it on before on after anything is fine because we are just demoing it the use case up okay on before um of insert an update I will do and in the actions will just trigger the event so you know what all is there in the incident so how if you are not aware how you can trigger the event you'll be triggering the same event which you have defined so it's the Syntax for it like GS Dot event queue okay and it has four attributes okay for input primary the first one will definitely be definitely and name for the event which you want to trigger the second attribute is the Glide record okay okay so here we our Glide record is current only right so I will be just passing current the third and the fourth one is Paramount and param two so as you can see the first is name which is string the second one is a glad record instance of any object the third one is pattern one and the fourth one is param two okay so I will just these are the primary one so what I will do I will give High High face and let's for instance I will give Ahmed perfect okay so I will save it out I'm just randomly passing anything out over there so this is done now what we'll be doing well go to the script action so the next step for us is like we have we have to Define script and I will create a new one with the name among now it asks which event will fire this particular thing out so I have to scroll it down down because I'm gonna take no longer it you are as T I can I can find find technomanc right this is the event you can Define the execution order I will make it active you can also Define the conditional script okay which will which will check whether it's get satisfied like for example current dot user has IDL role and all those things out right so you can check that particular thing out it's it's not a problem and now what you have to do you have to write your code over here so we can simply do it GS Dot dot info and I can give it as what we have over there we can give event sorry so what I will do let's grab that parents first right so variable event one equal to event Dot prm1 right this is a Syntax for it and in the similar way will give it four the other one also we went to as param two and then I can give event one plus last I will just give I will just incorporate space in between and we can give even an ideally it should work if I would just do Ctrl s now what we'll do we'll go back to incident just to check if it's working so incident and go to all incidents only will open any incident and I will update something out on that incident so let's and we will see how you can debug the things also right when it comes to event and script actions right so oh from the previous tutorial and it's not getting close okay so I will just update it to antivirus we have to just update anything out right save and the first and the foremost three one you have to check is whether the event got triggered or not so we will go to all and over your events event log to check whether the event got triggered or on as it's of no use right just bang our hand on other things so we can see the event got triggered with technomore hi hi it's an incident table and so on so this looks good now what we'll do we will go to the syslog so it says foreign this particular table and let's search for that particular message oh I will search for Amit and we can see the message came over here I am it from the script so everything is working fine for us now let's make this use case somewhat better was we have done a lot of promotion over here in this video right so let's go back and what we'll be doing we will be taking the username from the incident okay and updating on the incident okay with with um certain certain description now so what we can do I can give variable message equal to GS Dot get message and what we have to do high and it will be user so I will give High user okay you got one incident okay one incident and what should be given into column one with chatting array as second attribute one right and here we can give both the things out right I am not pretty familiar with the backend name so I will go to the field a lot of people are not using it out okay that's why I am showing it so it will be the first and the former thing we want to use that right so you can keep created by or call it let's take caller and the second thing what we want to do what we want is category writing so let's category category here it is okay and we will embrace it into that's how the get message box right and we will save it out so we are just passing oh we are not passing we have to pass right I forgot that thing out sorry for that so I will just take the event Cube from here control and you can either pass over your current dot caller ID or let's pass it separate Journey y to create this will create it in description as what we'll write into a script dictionary so I'll give it oh yeah current or caller ID the second one is current.category so you can do either on a business or you create a message or you can pass an entity over there and just play around it or in description so I am not doing any rocket science over there it's the same just have passed the dynamic attribute let's go back to the script action to play around with the information we got so now we will be updating incident only so I'll go to the script action technomore here we already have Paramount pam2 and that and whatever can do variable GI equal to new right record which will be on student table you can do cheat on dot cat and we can pass because we have the current objects right so let's use the current current dot says underscore ID you can do get value also but I am just passing it because that's not the concept for us and we can simply if Shia okay San what I have to do gr Dot short underscore description I can give hi we got an incident then from color we have right in the event one so I can give from event one let's use this all right use dot get message we'll play around it so you will be aware about the variable message [Music] and here we can put the message hi we got the incident from your passing color right from 0 will dynamically pass it out with cutting really as one I know no one likes incident pretty mean right so this is a message let's pass the dynamic attributes for the same we'll create an array and a capacity event one comma event two and we'll use this message to set the description message and then gr dot update we are done with the code let's save this out and see if it works oh now we have to update the incident out of it so how is the flow will go when we update an incident it will call an event that particular event will call the script action and that script action will update the incident again okay the flow of karma so I will go down to all let's play around the same incident they change the category again So currently short description is this right in the category again to email and we'll save this out it didn't get updated why why it didn't get updated oh it got updated now reload but why it's coming like this I think we've made some mistakes protection field ah one small mistake we have to separate it outrage because GS message has two entities one is the message and the second is the dynamic attribution for the scene let's go again go to the incident again it will change to I really don't like this problem again we'll change it to antivirus and I will save this out and we will wait for the pop-up to come the message to get updated mm-hmm you get updated you know is it coming the scene 01 everything seems to be okay let's change something out let's let's change this out I'm not sure or something hmm so you will not go with the message Maybe and then just copy this out one so the same we have to do it he went to and we will check the event log also once if it's coming next so let's go to the event and the event name is technobomb this is where we should have debugging knowledge also item one is one is coming as a display value why I didn't get that perfect so we have to go to the business rule and I have to change this out get okay Plus and now if I go to the incident um if I go now history to the incident I'll give it Hardware Hardware safe and the short description got updated hi we got an incident from Sister administrator with the categories system administrator I think I met I know no one likes things and I think I copied with the same thing even one only uh where I can show you that also so if we when I was copying I copied It event one event one on this let's fix this out also two save we'll go back again quickly to incident I'll change I get to Software and Save as you can see I got an incident from system administrator with category software I know no one else so this is how the script action works you can play around it like anything you want okay I just try to forecast on one of the use case which is pretty easy to understand you can make it pretty complex also so this is all for today's video I hope you like it out please like follow subscribe to my channel so that you'll get notified with my upcoming videos till then stay safe stay happy and have a nice day here thank you
https://www.youtube.com/watch?v=BiT2ifBRXQo