
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-29-2016 11:49 AM
Hello, We have several Client Scripts that call a Script Include to process data and send a response.
We use the evalJSON function to transform a JSON string to an object.
However, evalJSON is no longer supported in the Service Portal.
Is there a way to transform a JSON string to an object so that it can be dot-walked easily to retrieve the values?
We are using the technique here: https://fruitionpartners.eu/blog/2015/11/17/glideajax-return-multiple-values-using-json/
Script Include
var MyCustomAjax = Class.create();
MyCustomAjax.prototype = Object.extendsObject(AbstractAjaxProcessor, {
helloWorld: function() {
var obj = {};
obj.var1 = 'Hello';
obj.var2 = 'World';
var json = new JSON();
var data = json.encode(obj);//JSON formatted string
return data;
},
type: 'MyCustomAjax'
});
Client Script
function onLoad() {
var ga = new GlideAjax('MyCustomAjax');
ga.addParam('sysparm_name', 'helloWorld');
ga.getXML(showMessage);
}
function showMessage(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.addInfoMessage(answer); //JSON String
answer = answer.evalJSON(); //Transform the JSON string to an object NO LONGER SUPPORTED!
g_form.addInfoMessage(answer);
g_form.addInfoMessage(answer.var1); //Display "Hello"
g_form.addInfoMessage(answer.var2); //Display "World"
}
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-29-2016 01:33 PM
I have resolved this issue by using the native Javascript JSON.parse() method.
JSON.parse() - JavaScript | MDN
answer = JSON.parse(answer);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-29-2016 01:33 PM
I have resolved this issue by using the native Javascript JSON.parse() method.
JSON.parse() - JavaScript | MDN
answer = JSON.parse(answer);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-11-2016 11:05 AM
Hello,
JSON.parse doesn't seem to be working on the Catalog Client Script any help on this.
Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-12-2016 07:23 AM
This works for me... make sure that the UI Type is set to "Both"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-13-2017 05:15 AM
Thank you!
I did something like this so it will work for both the places.
var answer = response.responseXML.documentElement.getAttribute("answer"); //JSON string
try{
answer = answer.evalJSON();
}
catch(e){
answer = JSON.parse(answer);
}