What to chose between g_scratchpad, getReference and GlideAjax in ServiceNow

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[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 in this session we will talk about three ways of getting data on client from server you might get different requirement from your customers or clients in which you have to populate or use some data which is not on the form on the client and you have to pull that data from the server and utilize it on the form on the client service now provides three ways of doing those functionalities of pulling data from server to the client and the first functionality is g underscore scratch pad let's take a look so here's my personal developer instance now if i go to problem form and if i open any problem record let's see this one here we have this field called assign to now we do have this data assigned to however we do not have this user's email address directly on the form let's say you have a requirement you have to pull the data on the client maybe you have to populate a message the assigned to email address is something like that you have to populate that message so how can you use that because email address is not available here it's in users table and that is also for assign to so in that case what you can do you can do that with the help of g underscore scratchpad but how exactly you can define and use g underscore scratch pad so g underscore scratch pad basically works with display business rules that means g underscore scratch pad will only work when form is getting loaded that's the important part you have to understand before using g underscore scratch pad that your data will be pulled from the client when form is loaded and i will show you the whole mechanism the whole process that how exactly it captures that data from the server and then pushes to the client for that we have to write a display business rule and at the same time we also write a client script because we have to do we have to use that data on the client so in that case the field name we have is assigned to that's a field name we have so assigned to is the field name now i will write a business rule so i'm going to business rule i will click on new this is business rule new form so i will just give a name maybe use scratch pad and i will just make it advanced and here i will select display i don't have to put any condition maybe you can do assign to is not empty so i will do assign to is not empty now i am writing this for just one particular feature which i need to get but in this case if you will create maybe for your multiple requirements then you should not write multiple business rules you should definitely put all these conditions in the scripting part so as of now because i'm just using i'm just giving the demos that's the reason i'm just putting this value so assign two is not empty so i'm giving i'm just going here advanced now how exactly i will get that value because that value is already there on server side that is current because i can access that record and the value so in that case how exactly you declare g underscore scratch band so for that you just need to write g underscore scratch pad dot and you can just write maybe assigning and you can just do equal to current dot now here you can put the field name and you are done so what exactly it does now in display business tool what exactly it is doing it is capturing this value holding the value which you will get here but as you know if i will do current dot assign to it will just capture the society which i can also get directly on the client because i do have that option get value but i want email address so in that case what i need to do i just need to do here dot email that's a dot walk i have to do i have to get the email address from the assigned to basically it will do the dot walking to the user table and pull the email and then it will be pushed to underscore scratchpad so this particular scratchpad will hold that value and it will be basically available on the client but in the backend so that's what i'm doing so i have saved this value and now what i will do i will just click on save so it is done so i i think our business tool is ready and what i can do i will go to problem and i will create a client script here so i will create a client script now so that i have to populate that message so i will click on new so now whenever form will be loaded that value will be available and will be hold in in in that particular uh scratchpad variable which we created so that's a scratchpad object so now here i will just give populate assignee email and this will be onload and i just need to do g underscore form dot get info message the the email address of assignee is now i don't have that value on the form but i have that value in scratchpad objects so how exactly i will get it i just need to do here plus g underscore scratch pad dot assigning that's it and i can just click on save so let's test it and if i go to problem now you can see we are getting the message here the email address of assignee is problem dot coordinator underscore be at example.com and if i open this yep you can see that we do have same email address here that's something you can see we have same email address that means this email address was not available on the problem form but with the help of g underscore scratchpad we are able to hold that value and we are able to populate it on the form so that's how you can utilize g underscore scratch pad but the one thing you have to remember g underscore scratch pad will only work when form is loaded it will not work for any conditional change or something on chain it won't work it has to work when form is basically loaded the second way to pull server data on client is get reference so let's see how exactly you can use get reference to pull server data on the client now we will use the same functionality which you were working on and which you achieved with the help of g underscore scratch pad and you will see the difference so for what exactly i need to do i will go to same client script so i will go to the client script which we created so here is the client script and i will keep all these configurations as it is like we have to run it on load but we have to change the script for sure so i will make it full screen and then i'll make a little bit bigger and now i will start writing the script so what i will do now for get reference we have to first declare it so we have to capture that reference field value in one of the variable how exactly we can do that so for that we will do where user equal to g underscore form dot get reference now here i have to give field name and that is assigned underscore 2 comma now here i have to give callback function so callback function can be populate email this can be the function and then i will call this function so i will do populate populate email here i can put the parameter as user and now we have to put this message here now as of now you can see so what exactly it is doing it is basically capturing the value the reference value of assign to field and putting in this particular is this particular variable and then we are also calling this like using this callback function so that it does asynchronous call rather than synchronous call which will have lesser impact so in that case we are we are declaring this function so you have this populate email user now what i need to do i will i will remove this scratch pad which we used in our previous example now i have already disabled that business rule the one business display business tool which we used anyhow if you will not call it this will not use that value but whenever form will be loaded that value will definitely be holded in that particular variable scratchpad object so in this case i will just do user dot email that's it and now i will click on save once you will click on save your client script is updated and we will do testing now so we will go to the problem form any existing problem record let me open this one and let's see if you're able to get the message and yes you can see email address of assignee is this one problem dot manager and if i go a little bit bottom you can see problem manager assigned to is problem manager and email address should be the same this one which we just populated on the client so this is how you can use get reference for your different requirements of your customers and clients now the last not the least way of pulling data from server to the client is glide ajax and this is the most efficient way for pulling data from server to the client and very recommended approach even servicenow recommends this approach that whenever you have to pull data from server you should always use glide ajax rather than g underscore scratch pad or get reference i think g underscore scratch pad is still okay but it always runs that you have to remember that it always runs whenever form is basically loaded form is basically opened but if you will use glide ajax now this will be called whenever you have that kind of functionality then only it would be called it will not run every time but yes if your client script is on load then definitely you will call this glide ajax but for example even if you you are not using any g underscore scratch pad it will still be used it will still store that value even if you are not using it in your scripting so glide ajax is the recommended approach so let's take a look at how exactly you can achieve same functionality with glide ajax now if you remember we wrote that client script but for glide ajax we have to write a script include that's how you can client callable script include so for that what i will do i will go to script includes module and here i will just do new so we will create a new client script and i will just write glide ajax demo press tab we will make it client callable and here i will create a function so maybe i will do push or maybe get assignee now this is the function we have comma now here or how exactly i will get that value now you will you will get that value when when you will push that data that yes we do have this particular record search for that email address address and return it to me so that's how you will do that so in that case what you will do first i will get that value so we have user val user and this will be captured via this dot get parameter and here i can do cis per underscore user i will do semicolon now i will do where gr new glide record and here i will give the table name sys underscore user i will do gr dot sys on gi dot add query and here we will put the field that is justice underscore id and then i will do here we will capture this user if it is basically matching with the user and then i will do gr dot query that's it and if that user is available so that means gr dot next then in that case it should return user it should return gr dot um i can just do email that's it it will return that email address and that's that's what we want to populate on the form so that's what it will return now here is the parameter which you will get from client that means it will push that sys id so for that i will save this now so i have created this script include and now i will go to my problem and we will create or maybe added the same client script so i will go here i will go to client scripts here we have populate assignee email like this is not a big demo i'm showing you like it it doesn't it is it is basically it is basically not fulfilling uh i think i would say bigger features but this is just a demo that what are the differences you have for these three ways of pulling data from server to the client now here we have this so i will just maybe comment this one so now what i will do i will create a glide ajax variable so we'll initialize it so we will do ga new glide ajax and then you put script include name and our script include name is this one so i will put it here and then i will do ga dot add pattern now here you will put the function name and that you do y assist perm underscore name and here you put function name which you created and the function name is get assignee so i can put get assignee here and now i have to do ga dot and now the parameter which we have to send to a script include and that would be sis perm underscore user and i can do comma and here i can do gender score form dot get get value and the field name is assigned underscore 2. it will capture the society and then push it in the script include that's it and now i will do ga dot get xml and here i have to declare callback function so callback function maybe i can do populate assignee populate email and now i will do function populate email and here i can do response and i can do where answer equal to maybe i'll make it a little bit bigger screen as well maybe i will delete the whole script so that you can see so we have a ver answer and here i can do response dot response xml dot document element dot get attribute and here i can put answer and now i have to populate that message so how exactly we will do that we will do g underscore form dot add info message the email address of assignee is plus answer now i can just save this let's see if it works so our client script is created okay i have done this i think this this has already given me syntax error so yeah it should be good now now i will save it it is saved and we will go to our problem we will go to problem form and open any problem form let's see if we get it form is getting loaded it says email address of assignee is null so we're not able to get that value what can be the problem let's see maybe it is some issue with the script include maybe with the client script so onload ga new glide ajax we have given this ga dot add param we have function name uh add parenthesis underscore user we are also getting value assigned to ga dot egg get xml populate email and i'm using the same no difference and then we have answer equal to response that response xml document element get attribute answer um then the information email address is answer we are getting null so let me let me check that says sperm sperm it should be okay let me check that script include there should be some issue in that here we have user this dot get parameter says sperm user we have not made it a string and that's a reason and if i save it this time i have saved it and it should definitely return gr dot email so if i go to my problem so let me open this and if i open this problem and let's see if get yep we are able to get it now you can see we have this email address right here with the same functionality glide ajax so now you have seen we have achieved same functionality with three different ways of service now that is gender score scratch pad get reference and glide ajax but as i mentioned glide ajax is the recommended one which is more efficient as part of pulling the data from the server to the client so i hope you like my session you like this video please like share comment and subscribe to my channel for more videos and for more learning thank you and have a great day
Info
Channel: SAASWITHSERVICENOW
Views: 6,697
Rating: 4.9358287 out of 5
Keywords: incident management, incident, What Is ServiceNow, what is servicenow platform, servicenow training, servicenow administrator training, servicenow tutorial, servicenow tutorial for beginners, what is servicenow software, what is servicenow administrator, servicenow basics, What is Cloud, cloud service, ServiceNow Architecture, ServiceNow versions, ServiceNow Platform, introduction to servicenow, servicenow, g_scratchpad in servicenow, glideajax in servicenow, getreference
Id: LclUuP-gSNw
Channel Id: undefined
Length: 24min 36sec (1476 seconds)
Published: Sun Aug 02 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.