Could you Explain This Scratch pad variables and use (Business rule/workflow)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2018 10:57 PM
Could you Explain This Scratch pad variables and use (Business rule/workflow)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2018 11:19 PM
Hi,
you got 2 different scratchpads
1. The scratchpad that is used to send information between a display business rule and a client script/UI Policy. This is pretty much an alternative to making a GlideAjax Call on the client script instead. If you know you need data that isn't available on the form, you can run the code in a display business rule put the data in the scratchpad and the fetch that data when it's needed in the client script. Just beware that it might be better with GlideAjax in some cases. This since when using scratchpad, you get the data how it looked when the business rule queried it. It might perhaps be 5 min afterwards and for example your onsubmit client script needs the data. Then it can be old data which has been changed.
2. Scratchpad i workflow. This is used to send data between activities. Otherwise you can reach data that was fetch/calclated etc. from a earlier activity.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-22-2021 06:43 AM
If Possible, can you please provide the demo code for Point 1.
Please
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2018 12:52 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/
Hi Narender
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
03-22-2020 10:26 PM
Hello Naren,
The g_scratchpad object passes information from the server to the client, such as when the client requires information not available on the form.
Please refer below links, these might help you:
If my answer is helpful to you, please mark answer as helpful and correct.
Thanks and regards,
Megha.