- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-07-2021 10:07 AM
I am trying to pass an array from a script include to an onChange catalog client script, but no matter what I do, I keep getting the "Unhandled exception in GlideAjax" in my console.
Here is my script include:
fetchRoomNumber: function() {
var building = this.getParameter('sysparm_building');
var roomInfo = [];
var rooms = new GlideRecord('x_nuvo_eam_elocation');
rooms.addQuery('floor.building', building);
rooms.query();
while(rooms.next()) {
roomInfo.push(rooms.getValue('building'));
return roomInfo.toString();
}
return '';
},
and my Client Script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax('NEIUtil');
ga.addParam('sysparm_name', 'fetchRoomNumber');
ga.addParam('sysparm_building', g_form.getValue("u_building"));
ga.getXML(setRoomNumbers);
function setRoomNumbers(response) {
var answer = response;
if(answer) {
var arr = answer.split(',');
alert(arr);
}
}
}
I've also tried using
var arr = answer.evalJSON();
in my client script, but it throws the same error.
If I try to log "answer", then I get [object object], but any attempt to manipulate the array after that throws the error.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-07-2021 10:26 AM
I found another error on client side script.
The correct line of code has to be:
ga.getXMLAnswer(setRoomNumbers)
And please open your developer console to check which requests have been sent and what was the response.
Kind regards
Maik
If my answer replied your question please mark appropriate response as correct so that the question will appear as resolved for other users who may have a similar question in the future.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-07-2021 10:17 AM
Hi
I hope your Script Include code is just an excerpt because for the complete Script Include I miss some surrounding code.
But despite of this your code has to be as follows:
fetchRoomNumber: function() {
var building = this.getParameter('sysparm_building');
var roomInfo = [];
var rooms = new GlideRecord('x_nuvo_eam_elocation');
rooms.addQuery('floor.building', building);
rooms.query();
while(rooms.next()) {
roomInfo.push(rooms.getValue('building'));
}
return roomInfo.join();
},
Kind regards
Maik
If my answer replied your question please mark appropriate response as correct so that the question will appear as resolved for other users who may have a similar question in the future.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-07-2021 10:24 AM
Hi Maik,
Yes, it's just an excerpt.
I tried your suggestion but I am still getting the same error.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-07-2021 10:26 AM
I found another error on client side script.
The correct line of code has to be:
ga.getXMLAnswer(setRoomNumbers)
And please open your developer console to check which requests have been sent and what was the response.
Kind regards
Maik
If my answer replied your question please mark appropriate response as correct so that the question will appear as resolved for other users who may have a similar question in the future.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-07-2021 10:49 AM
Yes! This solved my issue thank you!