- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-14-2020 02:38 PM
I'm trying to create a global variable in a Catalog Client Script, available for all other client scripts to access:
var globalVar = '';
function onLoad() {
var ajax = new GlideAjax('TestScriptInclude');
ajax.addParam('sysparm_name', 'returnProperty');
ajax.getXMLAnswer(function(answer) {
globalVar = answer;
});
}
This onLoad client script calls to the server and gets an array of values that I need for other client scripts to use with onChange and onSubmit.
How do I set this up correctly and access it in my other catalog client scripts?
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-14-2020 03:45 PM
Be sure to uncheck "Isolate script" on all scripts using global variable.
- Declare global variable in onLoad.
- Set value onChange script.
- Can use it on other onChange script
Execution output:

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-14-2020 03:07 PM
So instead of var globalVar = ''; you just need to use globalVar = '';
Please mark this response as correct or helpful if it assisted you with your question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-14-2020 03:22 PM
Hi John,
Global variable can be defined in client script and called using g_scratchpad object but it does not work for service catalog form.
Please find the below snipped and related HI link below:
https://hi.service-now.com/kb_view.do?sysparm_article=KB0749175
Kindly mark my answer as Correct and Helpful based on the impact.
Regards,
Alok

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-14-2020 03:45 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-14-2020 03:54 PM
BINGO x 100! Thanks you so much!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-09-2022 04:12 AM
This works! Amazing. Thank you so much! My question is I do not understand why we have to declare the global variable onLoad, assign a new value onChange 1, then use it at onChange 2. I tried to declare the global variable at onLoad, then use it at another onChange but it does not work though.