Unhandled exception in GlideAjax in Service Portal

Farah5
Tera Contributor

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. 

1 ACCEPTED SOLUTION

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.

View solution in original post

5 REPLIES 5

Suseela Peddise
Kilo Sage

Hi,

Try below

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();

},

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;
var answer = response.responseXML.documentElement.getAttribute("answer");
if(answer) {
var arr = answer.split(',');
alert(arr);
}
}
}

 

If I have answered your question, please mark my response as correct and/or helpful.

Thanks,

Suseela P.