- 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 07:49 AM
When you say the script include will return the value shown - obviously it's not as you are getting null. That looks like an array, not JSON which would be more like
[{"field":"value","field2":"value"...
so in the script include, try returning something like
ArrName.join(',')
to return a string to the client
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2024 07:59 AM
After changing to ArrName.join(','), script include value like below but catalog client script still giving null
Script: ABC,AFG,AFD,AFCD,AFCND
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2024 08:04 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2024 08:08 AM
Sure, here you go
getName: function() {
var obj = [];
try {
var rest = new sn_ws.RESTMessageV2('ORGDetails', "Get Name");
rest.setRequestHeader('Authorization', 'Bearer ' + this.token);
var response = rest.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
if (httpStatus.toString().startsWith("2")) {
var parsedData = JSON.parse(responseBody);
for (var loop = 0; loop < parsedData.value.length; loop++) {
obj.push(parsedData.value[loop].Org);
}
gs.log("Return: " + obj.join(','));
return obj.join(',');
} else {
gs.error("Failed to retrieve Get Name: " + response.getErrorMessage());
}
} catch (ex) {
var message = ex.getMessage();
gs.error("Error: " + message);
}
},