- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2024 07:30 AM
The script include will return the stringify value shown below.
*** Script: JSON.stringify(obj): ["ABC","AF","EFD","CGED","AAAA","BBBB","CCCC","ZZZZZ",""]
I want value above to appear in a Select Box type of catalog variable. The catalog client script below returns null as an answer. What could have gone wrong?
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var gb = new GlideAjax('ORGANIZATIONAjazUtils');
gb.addParam('sysparm_name', 'getName');
gb.getXML(getResponse);
function getResponse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
alert("Answer: " + answer); //null is returned
var array = answer.split(',');
for (var i = 0; i < array.length; i++) {
g_form.addOption('client_company_name', array[i].toString(), array[i].toString());
}
}
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-17-2024 08:45 AM - edited 05-17-2024 08:45 AM
Hey @tsoct
I've gone through this in my own PDI, and the only way I was able to replicate what you're seeing was if the user triggering the change didn't have the role for the script include. Have you checked the SI ACL?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2024 08:05 AM
Are you getting the script value when the variable is changed - so you know for sure that this onChange Catalog Client Script is triggering this Script Include? Is the SI Client callable?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2024 08:09 AM
yes correct. SI's client callable is checked.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2024 08:19 AM
Are you getting the log for this
gs.log("Return: " + obj.join(','));
Hoping your script include is created in Global scope as gs.log does not work in custom scope. Also while returning can u try something like this
return JSON.stringify(obj.join(','));
Thanks,
Danish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2024 08:55 AM
Hello @Danish Bhairag2 , yes, all in Global scope
("Return: " + obj.join(','));
The above is returning :
ABC,AFG,AFD,AFCD,AFCND
JSON.stringify(obj.join(','));
The above is returning:
"ABC,AFG,AFD,AFCD,AFCND"
Both return null in catalog client script. and a red alert
There is a JavaScript error in your browser console
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-17-2024 04:54 AM
The error message explains the null return. Post the entire Script Include.