Help
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

g_scratchpad vs Gliderecord

diksh
Mega Contributor

Can someone please let me know typical differences and uses of g_scratchpad and Gliderecord. Please provide some examples as well. Also please explain the below code :

To populate the form scratchpad with data from a display rule:

//from display business rule 
g_scratchpad.someName = "someValue";
g_scratchpad.anotherName = "anotherValue";  
//if you want the client to have access to record fields not being displayed on the form
g_scratchpad.created_by = current.sys_created_by;
  //these are simple examples, in most cases you'll probably perform some other queries to test or get data

To access the form scratchpad data from a client script:

//from client script if (g_scratchpad.someName == "someValue") { //do something special }

Please let me know what is meant by the above example and if possible please provide me
some better example of passing the scratchpad value from a server to a client.

Thanks in advance!!

Regards,
Dikshit
1 ACCEPTED SOLUTION

Chuck Tomasi
ServiceNow Employee
ServiceNow Employee

A GlideRecord is an object used to interact with the database. For example, if I want to retrieve all active incidents,



var inc = new GlideRecord('incident');


inc.addActiveQuery();


inc.query();



while (inc.next()) {


  // Do something here


}



The g_scratchpad is an empty object you can use to push information (properties, objects, functions, etc.) from the server to the client. It is only available in display business rules and client scripts. I use it a lot to populate information on the form that is typically unavailable without an Ajax call.



When I teach this concept, I usually describe g_scratchpad as an "empty box" you can put things in for the client to open and use later.



Hope that explanation helps.


View solution in original post

7 REPLIES 7

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi Dikshit,



Please refer below blog and refer section 7 here (Scripting in Business Rules - ServiceNow Wiki )


Tip: Server side functions and client scripts


Anurag Tripathi
Kilo Patron
Kilo Patron

I dont really understand the question, scratchpad and gliderecord are very different things. Please elaborate.


-Anurag

Hey Anurag,



I totally understand the same that both are different things. I am still in my learning stage and i was not able to understand proper usage of both the things as its not very clear on Wiki. I wanted to know when both are server side, both can take advantage of fetching values from server than why cant i use glide record in place of g_scratchpad. I have started actively looking for knowledge in servicenow and i thank all you guys who put efforts to make people me understand basic stuff!!



Thanks and regards,


Dikshit


Hi Diksh,




As per the "Chuck Tomasi (CT)" conversation i understand like :




Chuck Tomasi (CT) is using the g_scratchpad as an Array or some object.


Generally when we open some record; It will open only the fileds that were added to the view.


If you want to show any of the remaining fileds you need to call a script include from glide ajax and have to return some values from script include and display the same to end user.


Instead of using all these GlideAjax and script include; Chuck Tomasi (CT) is suggesting g_scratchpad to write in the display business rule.




So that, While the display business rule is being executed you can set the values in to g_scratchpad(Arrya/object) and can access them on the form and display them on the form.




Thanks,


Varma