logo

NJP

ServiceNow Scripting Unleashed: Demystifying ServiceNow On-Demand Script Includes with Real Examples

Import · Oct 10, 2023 · video

[Music] hi all welcome back to our Channel today we are diving deep into the world of service now on demand script include if you ever wonder how to reuse script logic in service now this video is for you and On Demand script include also known as classless script in is a unique feature service now that allows you to Define single function that can be called from all the other server side scripts okay one thing to be noted right off the B on device script includes are strictly server side even if you select the client C option they won't work on the on the client side so without wasting any further time let's jump onto the instance and in today's use case what we'll be doing we'll be creating an on demand script include or classless script include uh with one function function and then we'll be defining a u action and calling that particular U action calling that particular script include from the particular U action so let's jump into so what we'll do the use case let's do we'll create a button on the problem okay from which we can create an incident okay so let's jump on and let's create a script first so I will be showing you how you can create class descript in so you have to just go to the script include module click on new okay this button I think most of the people will always already be aware about this Okay click on new and now now let's give the name okay let's we'll give it the name as create incident incident and now we know that we get this signature okay or definition for the class whenever class get created but when it comes to the class script include what you have to do over here just just focus on this particular part so over here what we have to do you have to just just take this name off okay remove the entire code we don't need any definition because we don't want any reference or any extended object kind of things right and you can simply Define a script function or with the name which should match the name of the script okay and then you can Define the attribute so o here will be uh giving the name as task record okay so we'll be passing a problem over here and then you can you can put your all your logic over you so for what what we'll be doing I will not add any validation for now but you can do it when when you are doing accident and it will be all s table make it big then G incident do initialize and let's set some attributes out for creation of incident so I will buing GI incident dot short description equal to a record star task record dot get value of the same short description and in the similar way we will be defining certain attributes out so let's define five five attributes so I will copy this out 3 4 5 so short description is what let's define description and it should be the description from the problem then what else we can Define let's define category which will be category then what assignment group let's take assignment group and the last attribute let's define the parent so that we can have the we can form the relation between ined problem so what we can do we can we can we can Define the parent attribute so it will be g dot parent and it should be we don't what any attribute value we want let's to ID perfect and then we can simply do gr do insert it's gr incident. insert and at last we can simply throw the message that the incident are created say do add message send created successfully so this is how you can Define our classes script included so you can see that there is no function defined there's only one function defined which for which the only criteria is like the name of the function should match the name of the script include that's it and we can simply save this all and this client callable option doesn't make any sense because if you are defining it also so it will it will not act okay it will not work because the client class list or on demand script in is completely driven on the server side okay because we don't have the the initialized object itself right so let's let's go I will just zoom out to the normal context and let's go and let's define a u action and we want the UI action on problem variable we'll give it a name as create s table will be problem no right and we can give it a name as form action and we don't want we want it on update not on insertion and now we can simply we don't when when we are using this out right um when we are using this classless script include okay we don't have to initialize it out we we can simply tle refer refer the script name and it will work for us so I'm forgot the name of the script include so let me just copy it out C go back to the U action and let's give the name is create script inter and we will pass the current object over here that's it and we will save it out did I to the form button let's see once I know I didn't so so this is done now let's jump onto the problem and let's see if something is assigned to me no I'll remove on the entire filter out let's open this particular problem out and now we should be able to see that button but we are not able to see that buttton why what is loading now you got stuck for me okay yeah it is there let jum again to the U action what we messed over here oh it didn't get reflected let's make sure that it got reflected perfect now we'll go to the history we want to open the problem record till we are not able to see that's oh now it's visible actually the form was loading now if you click on this button create incident it should create an incident so we got the message incident created successfully let's verify it out and if go I just want to bring all the fs out short description then there was a description then category let go with the S group I'm not pretty sure whether it was buil or and the most important was par and I will bring created by also created all saved and you can see this particular record go created just one way before so this is how you can use the classless or on demand script include the most the most important most significant aspect of this particular script INE is like uh you don't have to initialize the script out okay it's pretty easy to use you can simply initiate it from anywhere around the platform wherever the servers scripting are there okay so I hope this video is useful to you okay please subscribe to my channel so that you will get notified on my upcoming videos till then stay safe stay happy and eyes thank you

View original source

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