logo

NJP

#3 5 Use Cases of UI Action | ServiceNow Practical Use Cases

Import · Aug 09, 2020 · video

[Music] in order to subscribe to my channel please click here or click here please share comment and like my videos and channel hello guys welcome to sas word service now this is our third session of servicenow practical use cases in this session we will talk about five use cases of ui action scenario one there should be a button on incident form to copy incident details and create a child incident if i take you to my personal developer instance let's go to incident application and i will open a random incident racket let's say this one now the requirement is that users should see a button over here that if i want to create a child incident however it should copy some of the details from this current incident and create that child incident that means this incident will become the parent how exactly you can achieve this requirement now as we are talking about ui action so i will definitely create a ui action like these are the buttons we have related links all these are ui actions so what i will do i will right click over here i will go to configure and then i will go to ui actions it will show me the list of ui actions associated with incident and task and now i will create a new ui action by clicking this new button this is the new form of ui action now i will provide a name of this particular ui action the name basically would be visible to the user so i can give name maybe create and copy or copy or create child i can do copy parent and create child i will keep the table as it is incident table i have to give the action name action name i can give maybe copy parent underscore create child that's the action name we have to give now do i need to select client no because this is just it's kind of a server code which we have to run so it is there is no client involved in this it is it will just create an another incident so in that case i will select this one we will make it form button and then we will just come over here in the script field i will make it full screen make it little bit big and now i have to write the script now when this button will be clicked it will automatically run this server code now if you remember if you have learnt about ui action in a ui action you can write server side code and you can also write client-side code that means you can write both kind of codes as of now we are going to write server side code so here if i can do so i have to create a racket that means incident record how do we create incident racket you must have seen in my previous practical use case so what i will do i will do where gr equal to new glide record and here i can do incidents so here we provide the table name then i do semicolon and then i can do gr dot initialize initialize yeah i think it's correct spelling then i will do now as of now i'm initializing it now what details i want to copy now whatever details you want to copy you have to put it right here so in that case we will start with short description short description and we will do equal to current dot short underscore description semicolon now in this case it will copy the short description of current incident and now i can put gr dot color let's let's copy the caller id as well now when you will write similar kind of script or maybe you want to fulfill similar kind of requirement it's totally dynamic it's totally up to you what fields you want to pre-populate in that new incident and that's something you can write here so i'm just showing you the demo but you can add as many fields you want as per your requirement so i will do current dot color underscore id and that's a field name back in field name i can do one thing now so as of now i'm just copying short description and caller id but how the requirement is how you will make that new incident child of the current incident and how exactly we do that you have to use that parent incident field so on incident form there's a field if i take you over there and i go quickly here let me open a new record existing record not new record uh if i open this one and if i take to a little bit bottom in related rackets you can see we have this parent incident now we have to populate a new incident this particular incident so you have to push the value of this this incident number should be populated in new incident so in that case i will go to my ui action and what i will do i will write here gr dot parent underscore is that's a backend name so i will do pr dot parent dot incident underscore incident equal to you and that should be current incident so that should be under that's a reference field so we will push society of the current incident parent underscore incident and what we will do now now because we are doing this we are creating now you can also do one thing you can also populate work notes you can also mention that this incident was created from somewhere else so i can do gr underscore gr.work underscore not notes and then i can do this incident is copied from and what you can do here you can get the number field that means you have to get the number you have to post it and then you will do semicolon it should be good now and now i will do gr dot insert now as you know when you write the server script by creating a new racket you are done with this code but it's still one line of code which is really important what exactly then line of code not exactly to run this code because as of now this code will definitely run and this will create a new incident but the thing is because you will be on that incident racket now what exactly if user wants or your customer wants to reroute to that same new incident you don't want to be on on the current incident when you create it you go to the exam same new incident which you're going to create or which we have created basically so in that case you will go a little bit bottom here you can write this code action dot set now this will redirect the url redirect url in capital now where exactly we will route it to and that would be the record which will be created and that can be gr i will show you one difference as well so let me let me show you that first so we here we have action dot redirect uh gr and now i'm going to save this so my ui action is created this is created and if i go to maybe i will make it small a little bit so it is created i will go to any incident record let's say this one so yeah now you can see we have this button over here copy parent and create child if i click this particular button what would happen let's see if i click here you can see new incident is created with the same shot description and also with caller david miller and the best thing is in my previous practical use cases we have populated this particular message and you can see it has become the child of that same incident from where we created this incident so as of now as of now you can see we have re-routed it to the new incident now there is there is something you can change it as well what exactly is that um let me go to ui action again uh let me start it with updated because we can just go to our new button quickly now what you can do here if you will do current what would happen let's see now i am clicking on open because this is saved and i will open maybe this one it doesn't have any parent incident or 9001 and what i can do i will click here you will see the difference you can see that we still have that nine zero zero one that means it's still rerouted to the current incident but it still created that child incident how can you know that just go over here on the child incidence related list and if you click here you can see the number as well 33 now previous one was 32 and you it is the child of this particular incident so that means it has created that incident successfully by by re-routing so you can read out the urls as per your requirement as per your requirement from your customers and clients so this is how you can achieve this kind of requirement which we were talking about in scenario one scenario two there should be a button on incident form when user clicks the button system should update priority of incident to p1 and do not save the racket that means it should only set it it should not update it the update not the actual database racket how can you achieve this functionality let's take a look so we will go to incident first and if i come here and open any random incident now you can see that we have impact and urgency as low as of now but the requirement is if i click that new button this priority should be one and how exactly you can make it one by setting these values right that's how the requirement that's how the functionality is so in this case but but it should not update it like i'm doing right now so i'm doing it manually and it is becoming critical right now p1 but i need to do that that means user should click on that button and it should automatically set this racket to high and high that means impact should be high urgency should be high how exactly i can achieve this functionality and the important part is it should not save the racket so let me show you let me go to ui actions leave this page i will click on new to create a new ui action and i can do set set to p1 that's a name i will give which will be visible to the users action name i can give set to p1 that's it and i think we have to do this as well because it has to run on client now this is the difference guys as of now like in first scenario we were just talking about server code but now i'm going to write a client code so because i'm going to set it on client not on server so in that case i am populating this i'm checking this check box and we have to write a function name here as well because we have to call that function so i will write here set p1 that's a function name you are going to give maybe yeah set priority i think that's that's okay uh i can give demo the reason i'm just using these these words it might happen that servicenow might be using these functions for some ui action so i don't want to do any kind of conflict otherwise you will get some errors that's something you have to remember so i'm not using any other other function name so that's the reason i'm just keeping it separate so set priority demo now what i will do here i have to provide a function name i have to declare it so i will do function set priority and it's demo that's the name of the function so here we have function but i will make it a little bit bigger screen so that you can see the code properly now as this is a client script what exactly we need to use to set the value you have to use g underscore form yeah that's a client script we have to use set value and here i can do the field name that is urgency comma 1 and here i can do set value and i can do impact comma one that's a one is the basically backend value of high that's how it becomes priority one and that's it it will set the value so in that case i will just click on save so we will save this code now and we will also make it form button that's really important you shouldn't forget that i will save it again it is saved and now i will take you to incident uh let me open any incident maybe i will open this one i hope okay it's already priority one so let me open any non-priority one incident like this one so you can see we have written the code and if i click on set to p1 click it you can see that it has set the value on client it is not saved if i will reload the form you will see it will go back to the same value which it was earlier but if i click it here again it will set the value and you can see the priority has become critical and i can now save it i can update this particular incident as of now it is showing this particular button in every condition even its p1 incidence in that case i will do one thing i will go to my ui action in ui action there is a field called condition now this condition is something for the visibility of this button that what condition what condition you want to show this button so what i can do i can do current dot and urgency basically maybe you can you just do priority not urgency and impact both so i can do current dot priority is not equal to one and i think that's it it should work and if i save this and if i open any incident now you can see that priority is p1 and that's the reason i'm not able to see that button however if i make it down you will see the magic and i save this okay it's asking me for mandatory field i will put something like this and now i will save this when form is getting loaded with save you can see that we can see that button now set to p1 so this is how you can set the basically change the field with the help of ui action as per the requirement you have from your customers and clients and that's how you can achieve this kind of scenario if i click set to p1 again you can see it got changed scenario 3 there should be a button on incident form when user clicks the button system should update priority of incident to p1 and save the racket now this is kind of i would say same requirement however the difference is in previous scenario we were not saving the racket automatically but this time you have to populate the priority as well that means urgency impact and priority at the same time you have to save the racket that means a user clicks the button it should just save the racket without asking anything now in this case basically two things are involved client-side code and server-side code as well so it's totally up to you how exactly you want to do that scripting because when i say client side maybe we will show an alert that hey user you are going to change the priority and then you will update the racket so in that case if i take you to my personal developer instance and the requirement we have i think it's kind of same requirement as i mentioned you just need to save the racket so how can you achieve this what i will do i will edit the same same ui action which we created so or maybe we will create a new one so that it will be really i think helpful you to understand because i will also update this code in my description as well so you can find the whole update set and if you want to try in your personal developer instance you can do that as well so i think i need to go to ui actions that's what we will go here we have set to p1 and now i will go to here and we will create a new ui action here we will do set to or maybe update to p1 that's a different name we will select update to p1 action name i can give update to p1 and yes i i do need a client code as well do i need a on click function yes i do need it so maybe i will do update 2p1 demo so now this is the function name which we will call in our script now here is the script field and yeah i think we can just make it form button and that's it for now and we have all these details i will make it full screen because i have to write the code now now we will write the code we will start with our client code so for that i will do function and the name of the function which we used i think i have to use that so let me check first and then that's a this function and i will do curly brackets now here i have to co write the code now as you want to update the racket what exactly you need to do because you have to update the racket as well by setting the value and you have to update it in that case i think you don't have to set the value directly on the client what you can do maybe you can just put the alert that's what you're going to do so in that case i will write ur going to upgrade the priority of incident to p1 this is an alert which we want to show to the user when they will click this button now this is the client code now there's another line of code which you always need to add and that's kind of a recommended approach while you will use ui action with client and server and that is gs ft submit then we will do null and we will do g underscore form dot get form element now here you have to write the action name which you created so if i go here we have this action name we have to just copy it we will go to our script and then i will write the name here in string that's it now why exactly we are doing this now we are doing this because you have to execute the server side code as well and that's the reason you you definitely need to call that action so that your server side code can run like like you do like you did in the first scenario that because in that case you you don't have to mention specifically because that's how that particular ui action will will proceed but in this case because you are using client and server both you have to provide that action name which you want to call so that's how you provide so that it can execute the server code as well now where is your server code for updating the rackets now before that before we write that code what you need to do because if you if you want if you don't want any kind of error that means you have to ensure while you run the server code there should not be any browser error in that case you have to write here if i can do type off window now this is the syntax while using client and server so you do like this and if it is undefined undefined here i have to call the function where you will write the server code and that function should be maybe update priority update priority demo maybe update priority and i can just do like this and semicolon now you have to declare that function same function so i can do like this function here i will just copy this paste it here now i have to write that code basically you have to update the priority now how exactly you can do that for that we have to do current dot urgency equal to 1 i can do current dot impact equal to 1 and i can do current dot update because it has to update the racket now another important thing you have to do is redirection of url so we will just do action dot set redirect url and here i can just type current that's it so we have action dot set redirect url and here we have current it is giving me a mixed spaces that's fine just click here it will solve it now your code is ready and i think it should be good i will just save it now i'm saving it so our ui action the new ui action is created now what we will do we will go to our incident racket existing incident racket maybe this one and i have this particular incident so we have two buttons set to p1 or update to p1 set will if you remember we'll just set it on client but i want to update it as well if i click on update to p1 you will see the error you are going to upgrade the priority on incident to p1 and if i will close this this will update it you can see it is updating and you can see now incident is updated so priority is p1 now and if i reload it because this has been updated in the database so now it is p1 we are still seeing this button you can see that but you can change the condition as i showed you earlier for set to p1 so this is how you can achieve this kind of requirement for your customer and clients and write same code same ui action but with two different codes client script and server side script scenario 4 there should be a button on problem racket to create two problem tasks automatically associated with the same problem so this is my personal developer instance and if i go to problem racket any problem bracket let's say this one the requirement is that i should have a button over here and if i click that button it should automatically create two problem task maybe by copying few information from this and it should also tag it as a problem parent should be this one and then it should have two problem task racket with that same button and it should be a server side code because we're not doing anything on the client in that case i will go here and i will go to ui actions and i will click on new because i will create a new ui action i will give it a name so maybe create p task p tasks and i can check this box form button i can give it a name create p tasks i go a little bit bottom it's not client so i'm not going to click on client and i will make it big screen and make it a little bit large now i will write my code now it's the same thing because you have to create the racket so as we did earlier you have to do the same thing so in that case but but the thing is how many times you have to create this racket two times maybe different different uh shot description maybe let's say so maybe test shot description one test shot description two that's a problem tasks or description how can you achieve this so if you remember in my previous practical use case we used array similarly we will do it here let's see that so what i will do i will first maybe declare uh create a variable maybe add a type of variable so maybe that will be where sd that's a short description so sd and i will put the short description here maybe test demo one that's a string comma and i can do test demo two now this is the error we have created now i'll do four so we will run the for loop and i will do i equal to zero semicolon and i will do i less than equal to sd dot len gth lens semicolon and i will do i plus plus now i will initiate that glide record object i can i will initialize it to create problem task let me check the name of the problem task table so if i go to problem that's very important to see before i write the code i will any i will open any problem bracket go to the related list here we have related list i don't have any maybe if i click on new maybe click on general and it's problem underscore task so i think and here we will pre-populate those two short descriptions that's what you have to populate and i will maybe we will copy description or maybe short description to description that's something we can do for sure so i will close it i will go to my script now now here we will do where gr equal to new glide record and i will give problem underscore task that's a table name and we will initialize it initialize it initialize now we will set the shot description how we will set it so we will do gr dot short underscore description equal to and that's the one we will do sd and we will just do i so that it will pick that value and here we will do gr dot now we will have short description now description equal to you and that will be from current problem may be able to current dot description and we have to copy short description of current problem so i will do short underscore description we will do semicolon here so initialize short description now we also need to populate the problem record so if i take you to the problem and that's how it will become the parent so if i open any problem i have opened incident by mistake we will go to problem and if i open any problem record and go a little bit bottom in the related list i don't yeah we do have a problem task and if i come here yep we have this one so the the name of the field is let me see that the name of the field is problem we also have this uh type field so if you want you can do that problem underscore task type so if you want to pre-populate you can do that and if i see the choices what all choices we have let me take a look quickly we only have two choices general and rca so let's create maybe uh these two or maybe let's just create one with general and i can do i will close this now here i will do gr dot problem equal to it should be current dot cis id sys id and i can also put the type so it's problem underscore task underscore type i hope that's a correct name and i can just put the value here general that's the value we have so it will automatically populate it it is initializing its fine short description description everything should be okay and now i will insert it so we will do gr.insert now do i need to redirect the url as well basically you will have two problem racket so in this case you won't be redirect i think otherwise user will be confused so i don't think you have to redirect but you can redirect to the same record which you have here so for that i can do i will come here and i can do action dot re direct url and i can just put current that's it your code is ready you will format it and i think it should be good we should not have any kind of issue we will have we have sd dot length sdi yep we will save it now it should work so it is saved and now we will go to our problem so it is saved we will go to problem we will open any problem and maybe let's say this one so we have this button if you remember we named it as create p tasks and if i go a little bit bottom so we do have one problem task but that's okay i will just click on create problem task it will reload it but it didn't reload to the same racket even we did that but let's see if it created two tasks and yes it created it created test demo one and here we have test demo two but the thing is it also created third one why exactly is that we will see that but that's okay we still got the same two two uh like whatever shot descriptions we had test demo one with the type general and if i click here you will see that we also have this problem record here and we have also copied the short description unknown source of sap outage so in this case let me go to my code first so i will go directly to my record maybe i will go from here i will click open here's my problem bracket and i will go to ui action we have ui actions i will go over there we have this create p task let's see that what exactly the issue could be so if i go to the bottom i will make it full screen i think this is the problem it should be i think because uh the length i think length is but two that i is less than equal to so okay because it it will basically uh it will basically loop three times zero one two so it should be less than equal to less than or the length of length of this array and we only have two values and that's the reason it will not create the third one now uh but let me check redirect i think this one i think we forgot the we i think this is the wrong command we used here it should be set and it should be set redirect that's what the correct syntax is and now this will definitely work perfectly so if i click on save and i open my problem record let me go there problem problem and let me open this one unable to connect to vpn it's open and if i go i will make it a little bit smaller as well so that you will be able to understand better as of now i don't have any problem task associated with this problem bracket i just need to click on this button click on it action taken form is still the same it basically redirected to the same form and let's see if magic happened or not if i go bottom yes we are able to create two problem task records with the same type with the test demo and let's see the short description description you can see that we have in description we have short description of problem so that's how you can achieve your requirement you can create multiple records you can do these kind of functionalities you can fulfill the requirement of your customer and clients with the help of these kind of functionalities this was scenario four we were talking about scenario five there should be a button on problem form to open new incident form so that user can create new one just the new incident form from problem form so in my personal developer instance we will go to problem record and i will just create a new ui action so ui actions here i will click new we will give it a name as create inc or maybe rather than that you can do open inc and higher i can give open underscore inc that's the action name we are giving to our ui action form button here now here because for opening an incident form we have to redirect the url so in that case i will just create the url first what that url would be so it will be the string i will do slash incident dot do question mark and if i do says underscore id equal to minus one whenever you will do like this in your url it will open up the new racket for any any table so in this case i will do semicolon now and i will do action dot set redirect redirect url and i will just give url here and semicolon it should be good we should be able to get this url and i will make it a little bit bigger for you so that you will see my code and so this is the code not much just two lines of code action redirect syntax is good everything is good i will just save it and we will do a quick testing so it is saved now i will go here i will open up the problem racket because this ui action is on problem bracket i will open any problem so here we have open inc and if i click this button you will see the magic click this button it will reload you can see that from directly from the problem form we are able to open new incident form so this is how you can create this ui action and fulfill the requirement of your customer and clients for scenario five so these are the few examples five examples five different scenarios of ui actions you can fulfill the requirements for your customers and clients this is just a demo but similarly if you have similar kind of requirement you can definitely complete them for your customers so i hope you liked my video please do subscribe my channel like and share for sure thank you have a great day

View original source

https://www.youtube.com/watch?v=Xvk-8KfYl28