Explain scratchpad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-25-2019 01:24 AM
Hi All,
Could someone please explain when, where and why do we scratchpad and some examples. I would like to learn the concept 🙂
Regards
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-25-2019 01:31 AM
Hi,
The g_scratchpad object passes information from the server to the client, such as when the client requires information not available on the form. For example, if you have a client script that needs to access the field u_retrieve, and the field is not on the form, the data is not available to the client script. A typical solution to this situation is to place the field on the form and then always hide it with a client script or UI policy. While this solution may be faster to configure, it is slower to execute.
If you know what information the client needs from the server before the form is loaded, a display business rule can create g_scratchpad properties to hold this information. The g_scratchpad is sent to the client when the form is requested, making it available to all client-side scripting methods. This is a very efficient means of sending information from the server to the client. However, you can only load data this way when the form is loaded. The business rule cannot be triggered dynamically. In those cases, use an asynchronous GlideAjax call.
For example, assume you open an incident and need to pass this information to the client:
- The value of the system property css.base.color
- Whether or not the current record has attachments
- The name of the caller's manager
A display business rule sends this information to the client using the following script:
g_scratchpad.css = gs.getProperty('css.base.color');
g_scratchpad.hasAttachments = current.hasAttachments();
g_scratchpad.managerName = current.caller_id.manager.getDisplayValue();
To access scratchpad data using a client script:
// Check if the form has attachments
if (g_scratchpad.hasAttachments)
// do something interesting here
else
alert('You need to attach a form signed by ' + g_scratchpad.managerName);
Mark it as correct/helpful,if it helps.
Regrads,
Ragini

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-25-2019 01:34 AM
Hi,
scratchpad
The scratchpad in workflow is a space in the workflow context to store and share string based variables (as name:value pairs) between instances of activities within an executing instance of a workflow.
The scratchpad is global to the instance of the running workflow and as such, is available equally to all activities.
Declaration
workflow.scratchpad.variableName = variableValue;
Display
There is no way to view the contents of the scratchpad.
Access and Assignment
workflow.scratchpad.variableName = variableValue;
var myValue = workflow.scratchpad.variableName;
Mark it as correct/helpful,if it helps.
Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-25-2019 01:45 AM
Please find the below link and info ,if helpful mark it as helpful and like
https://servicenowgems.com/2016/10/10/understanding-scratchpad-g_scratchpad/
This is a really old thread, but I'd thought I'd clarify the issue regarding using Objects with g_scratchpad for anyone else who may read the post.
You can create Objects in your Display Business rule and then copy them to the g_scratchpad Object.
For example:
- var myObject = {name:"Jake",title:"Senior Technical Consultant"}; // create JavaScript Object
- g_scratchpad.myObject = myObject; // copy JavaScript Object to global Object
This Object would then be available in your Client Script by accessing the scratchpad:
- alert('Name: '+g_scratchpad.myObject.name);
The reason you cannot simply copy your User record Object (e.g grTest) to the scratchpad is because it is NOT a JavaScript Object. It is actually a GlideRecord Object, and even the "field" properties of such an Object are not native data types (e.g String, Number, Boolean etc). To successfully copy a GlideRecord Object you would need to first convert it to a JavaScript Object, and then copy that to the g_scratchpad Object in your Display Business Rule. You could do this by type casting (converting) each of the field values from the GlideRecord to String properties in your new Object. For example:
- // Display Business Rule
- var userObject; // define null variable/object
- var fieldsToCopy = ['name','email','title']; // array of fieldnames to copy
- var grTest = new GlideRecord('sys_user');
- grTest.addQuery('sys_id','681ccaf9c0a8016400b98a06818d57c7'); // update with dynamic sys_id value
- grTest.query();
- if(grTest.next()) {
- userObject = {};
- for(var i=0; i<fieldsToCopy.length; i++){ // loop through fieldname array
- var fieldName = fieldsToCopy[i];
- if(grTest[fieldName]) userObject[fieldName] = ''+grTest[fieldName]; // copy field value
- }
- }
- if(userObject) g_scratchpad.userObject = userObject; // copy Object to scratchpad if not null
You could further enhance this function by converting some of the fields to either Number or Boolean if need to, but the above script will allow you to copy an "Object" from server to client via g_scratchpad, even if the originating data was a GlideRecord (e.g User record).

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-25-2019 03:02 AM
Hi Nani,
Please Mark it as correct/helpful, if it helps.
Thanks