g_scratchpad

Community Alums
Not applicable

I am new to ServiceNow and trying to learn client scripts

can someone explain about g_scratchpad in details 

2 REPLIES 2

Chaitanya ILCR
Kilo Patron

Hi @Community Alums , 

g_scratchpad is a special object in ServiceNow that allows you to pass data from server-side scripts (specifically display business rules) to client-side scripts. This is particularly useful when you need to use server-side information in your client scripts without making additional server calls.

 

you can refer below blogs

https://www.servicenow.com/community/developer-articles/display-business-rule-and-g-scratchpad/ta-p/2321189

https://www.servicenow.com/community/itsm-articles/quot-use-of-server-side-script-g-scratchpad-and-client-side/ta-p/2302411

 

and youtube video

https://www.youtube.com/watch?v=77D7DMIaG24

 

 

Please mark my answer as helpful/correct if it resolves your query.

Regards,
Chaitanya

g_scratchpad object is used to pass information from service to client. I this video i have provided the brief demo that how we can use g_scratchpad in servicenow and how we can use g_scratchpad object in display business rule (server side) and in client script (client side). Please visit below ...

jcmings
Mega Sage

So you can pass data from the server-side to client-side using a display business rule and the g_scratchpad object. Each item you pass (a "property") is sent as a string. Check out the below example:

 

You are on the Incident [incident] table. You create a display business rule to send over some information. Your business rule looks like this:

g_scratchpad.city = current.requested_for.city;
g_scratchpad.country = current.requested_for.country;

 

So in the above BR, we're grabbing the requestor's city and country from their User [sys_user] record. The city and country are both properties of the g_scratchpad object. 

 

You can then use a client script (any type of client script) to access that value. So your client script could do something like this...

g_form.setValue('description', 'Requestor is located in ' + g_scratchpad.city + ', ' + g_scratchpad.country);
//Output: Requestor is located in Munich, Germany

 

Long story short -- this is how we can pass server-side data to the client for usage in a client script. Some people use the scratchpad to pass a system property value to client scripts. There are various use cases!