- 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 02:41 PM
I don think that is possible at all. What is your use case
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 02:49 PM
The use case is simple...better readibility and maintainability of the code to keep most of the logic in Catalog Client Script, keep it in one place. Do not want to call the same script include in glide ajax, onChange, onSubmit, onLoad to just get this property.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-14-2020 02:51 PM
Then you need to create a variable and store it in the variable of catalog item. I dont think there is a concept of global variable in catalog client script.
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 02:54 PM
Yes there is, I've tried it myself.
https://community.servicenow.com/community?id=community_question&sys_id=1caa472ddb5cdbc01dcaf3231f961956
I could access this in other Catalog Client Scripts in that Item.