We are adding quite a bit of information to the g_scratchpad object on a project I'm involved with at the moment so I decided to create a quick tool to help us see what all ends up there.  It's a simple client-side Related Link UI Action that pops up a window with the current contents:



1. Here's the configuration for the UI Action:

Name: Show Contents of g_scratchpad

Table: Global

Order: 100,000

Action name: u_show_g_scratchpad

Active: checked

Show insert: checked

Show update: checked

Client: checked

Form link: checked

Hint: Displays the contents of the g_scratchpad object in a popup window

Onclick: u_showGScratchpad()

Condition: gs.hasRole("admin")


function u_showGScratchpad(){
    var newLine = "~~~newline~~~";  //will be replaced with line breaks in the UI Page
    var scratchPad = "";
    var items = Object.keys(g_scratchpad);
    items.sort();  //sort the item names alphabetically in case they are not already

    var numberOfItems = items.length;
    for (var i = 0; i < numberOfItems; i++) {
        scratchPad += items[i] + " = " + JSON.stringify(g_scratchpad[items[i]]) + newLine;

    //encode the string so it can be passed to the UI Page properly and then decoded there
    scratchPad = encodeURIComponent(scratchPad);

    //open the dialog window
    var gdw = new GlideDialogWindow("u_simple_copy_paste");
    gdw.setTitle("Contents of g_scratchpad");
    gdw.setSize(650, 500);
    gdw.setPreference("sysparm_text", scratchPad);



2. The pop-up UI Page:

Name: u_simple_copy_paste

Category: General


<textarea id="u_text_area" style="width: auto; height: auto;" rows='15' cols='100' title="Text you can copy and paste">
<div align="right">
<button class="btn btn-default" id="cancel_button" onclick="(window.GlideDialogWindow || window.GlideModalForm).prototype.locate(this).destroy(); return false" style="min-width: 5em;" title="" type="button">Close</button>


Client script:

try {  
  var search = "~~~newline~~~";  //text we want to replace  
  var replace = "\n";  //the text we want to use  
  var textArea = gel("u_text_area");  
  //set the text string into the text area control, first decoding it and replacing the search string with the replacement string to insert proper line breaks  
  textArea.innerHTML = (decodeURIComponent("${sysparm_text}")).replace(new RegExp(search, 'g'), replace);  
  //auto-select the entire text  
} catch(err) {}


The UI Page is the same one used by "Preview GlideRecord Script" Tool  and "Grab Grouped Information" Tool.  This one is slightly updated - I've added a "Close" button to the form.  You can use the existing UI Page as is if you are using either of the other two tools, or update the HTML field with the code above to add the button.


I've attached the XML files for both the UI Action and the UI Page if you want to just import them into your instance.