- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā09-29-2020 06:14 PM
I understood GlideAjax to return single values as very simple and getXMLAnswer() is very easy to use. To return multiple values or object or array what is recommended for someone to start learn and practice from the beginning if never tried?
I find two approaches one with XML (newItem method) and other JSON.encode/parse. Appreciate any recommendation on what approach to practice or any scenarios that both are needed in different situations and any link to get started.
Wondering any approach is recommended as best practice or each has its own use cases.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā09-29-2020 06:46 PM
Hi,
The best resource I can give you is the GlideAjax cheat sheet. It literally breaks it all down for you AND shows you how to return multiple values: https://community.servicenow.com/community?id=community_article&sys_id=9f7ce2e1dbd0dbc01dcaf3231f961...
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā09-29-2020 06:45 PM
Hi Giri,
Here is the blog on this topic.
https://community.servicenow.com/community?id=community_blog&sys_id=161d62e5dbd0dbc01dcaf3231f961933

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā09-29-2020 06:46 PM
Hi,
The best resource I can give you is the GlideAjax cheat sheet. It literally breaks it all down for you AND shows you how to return multiple values: https://community.servicenow.com/community?id=community_article&sys_id=9f7ce2e1dbd0dbc01dcaf3231f961...
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā09-29-2020 07:10 PM
I usually use JSON.stringify() on the script include over xml because JSON is easier to use with JavaScript than XML (Well, JSON does stand for JavaScript Object Notation). The only case when I use XML nowadays is to process SOAP messages.
On the service side, just .push() items into an array and JSON.stringify() on the return statement.
On the client side, I'll need to do a response.reponseXML.documentElement.getAttribute("answer") to get the value.
ajax.getXML(_processDataFromServer);
function _processDataFromServer(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
var jsonItem = JSON.parse(answer);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā09-21-2023 11:51 AM
In my UI Page client script, callback function (argument of ga.getXML()), I had to use querySelector ...
var ga = new GlideAjax('ReceivingReportAjaxCall');
// your GlideAjax script include class name is ReceivingReportAjaxCall
ga.addParam('sysparm_name', 'getVendorsThisMonth');
// Replace getVendorsThisMonth with your (e.g., getRecords) GlideAjax
// function name within the Script Include class (ReceivingReportAjaxCall) declaration
var lclYear = getDesiredRRYear();
var lclMonth = getDesiredRRMonth();
ga.addParam('sysparm_rr_year', lclYear);
ga.addParam('sysparm_rr_month', lclMonth);
ga.getXML(getVendorsJSON);
also in my UI Page client script ...
function getVendorsJSON(response) {
var answer = "";
step = 1.1;
// alert('getRecordsJSON');
try {
answer = response.responseXML.querySelector('xml').getAttribute('answer');
// above line retrieves
// the response attribute for the 'getRecords' function you defined in your server script.
step = 2;
if (answer) {
step = 3;
// Process the response data (assuming the response is a JSON array)
var data = "";
try {
data = JSON.parse(answer);
//alert(step + '. data is: ' + data);
}
catch (error) {
alert(step + '. data catch: ' + error.toString());
}