GlideAjax return [object Object] instead of incident number

bbf3562
Kilo Guru

I couldn't figure out why I am getting list of [object Object] instead of incident numbers in client side. Here is screenshot example,

find_real_file.png

According to gs.log from ajax script, it able to display 16 correct incident number,

find_real_file.png

I am pretty sure I am not using a right   returnJSON function. Do I need to decode or something?

Here a sample of my script,

var groupId = 'ad057f9d4f374200c93959dd0210c704';

  alert("Group name is " + groupId);

  var ga = new GlideAjax('OpenIncidents');

  ga.addParam('sysparm_name', 'getincidents');

  ga.addParam('sysparm_item', groupId);

  ga.getXML(IncidentsParse);

 

  function IncidentsParse(response){

  var answer = response.responseXML.documentElement.getAttribute("answer");

  answer = answer.evalJSON();

  //alert(answer.length);

 

                  var count = 1;

  for(var i = 0; i < answer.length; i++)

  {

  var myTr = "myTr" + count;

  var ticketTd = "ticketTd" + count;

 

  alert("ticket is "+ answer[i]);

  var row = document.createElement("tr");

  row.setAttribute("id", myTr);

  document.getElementById("myBody").appendChild(row);

}

1 ACCEPTED SOLUTION

can we have like,



ans[i] = gr.number.toString();


View solution in original post

9 REPLIES 9

Shishir Srivast
Mega Sage

Can you replace this line


answer = answer.evalJSON();



with


answer = JSON.parse(answer);


I still get same results of [object Object] with answer = JSON.parse(answer);


Looks like little modification required in for loop as well.


Please change this


for(var i = 0; i < answer.length; i++)


to


for(var i = 0; i < answer.length; i++)


&lt; has nothing to do with error and plus that script is in Jelly which use html tag. Using "<" will cause unrecognizable script error so &lt; will need to use for "<" in Jelly.