Can I set a g_scratchpad variable on a catalog client script for later use?

Uncle Rob
Kilo Patron

I have an onLoad client script that looks like... (onchange of remit_to variable)

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
g_scratchpad.holder = newValue;
}

 

I can't alert g_scratchpad.holder though.  Is g_scratchpad not meant to be used this way?

17 REPLIES 17

Try "setPreference()" then:

http://www.john-james-andersen.com/blog/service-now/servicenow-user-preferences-server-client-access...

Then its set serverside and not client side and should be available as long as the user is logged in

Shekhar Deshing
Mega Expert

I can able to see the alert when Incident form load 

function onLoad() {
//Type appropriate comment here, and begin script below
alert("Working OK"+g_scratchpad.priority);
g_form.setValue('u_string_4',g_scratchpad.priority);
g_scratchpad.holder = "newValue";
alert(g_scratchpad.holder);

//g_scratchpad.someName = "someValue";
//g_scratchpad.anotherName = "anotherValue";
}

=======================

On Display Business Rules we can set the g_scratchpad 

find_real_file.png

 

Above scenario is working fine for me however you can create the new form field where you would like to (set or save the value).

Suppose if you create any field on the Incident form and apply globally however that will be visible for all incidents.

What exactly your requirement.

Please mark helpful or mark as answer if working for you.

Thanks,

 

Kiera
Tera Expert

Hi, not sure if this is still an issue but thought I'd chuck it here just in case it helps someone else.

 

Frustratingly, g_scratchpad only seems to work in the portal UI and not in desktop.

 

However, I have managed to use window.attribute_name in the desktop UI which does allow you to share values between multiple scripts and works exactly the same as g_scratchpad (although I have no idea whether or not this would be considered best practice).

 

Hope this helps 🙂