Service Portal throws "Unhandled exception in GlideAjax" error in the console when a client script uses evalJSON()


Description

Symptoms


Console throws an error "Unhandled exception in GlideAjax" in Service Portal on a catalog item with a client script that uses evalJSON();

Release


ALL

Cause


This is caused as evalJSON() is not supported in the portal and returns null. 

Resolution


Use JSON.parse() instead in the client script. 

 

For example change the client script from:

 

var ga = new GlideAjax('GetUserInfo');
ga.addParam('sysparm_name', 'getUserInfo');
ga.getXML(updateUserInfo);

function updateUserInfo(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
if(answer){
var data = answer.evalJSON(true);
g_form.setValue('employee_username', data.user_name);

}
}

 

To:

var ga = new GlideAjax('GetUserInfo');
ga.addParam('sysparm_name', 'getUserInfo');
ga.getXML(updateUserInfo);

function updateUserInfo(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
if(answer){
var data = JSON.parse(answer);
g_form.setValue('employee_username', data.user_name);

}
}