- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2019 01:42 PM
Here's the situation: I get an XML object back. The problem is that it only ever has the elements and attributes that were added during the request. I can't get an answer/value back from the server.
I have a UI Action calling a Script Include. The Script Include is in the Global app and the client-side UI Script is in Audit.
Here's how the Script Include is setup:
Here's the Script Include code:
var prettydiffSN = Class.create();
prettydiffSN.prototype = Object.extendsObject(AbstractAjaxProcessor, {
initialize: function (){
var result = this.newItem("result");
result.setAttribute("message", "The great payload");
},
type: 'prettydiffSN'
});
Here's the client-side code (in a UI Action, with the Client box checked):
function runPrettyDiffPrev() {
jslog('prev Version ui action');
var ajax = new GlideAjax('global.prettydiffSN');
ajax.addParam('sysparm_name', "initialize");
ajax.getXML(getDiffCode);
}
function getDiffCode(response) {
var doc = response.responseXML.getElementsByTagName("result");
var message = doc[0].getAttribute("message");
jslog(message);
}
Here's the result:
<?xml version="1.0" encoding="UTF-8"?><xml sysparm_max="15" sysparm_name="initialize" sysparm_processor="global.prettydiffSN"/>
Actually, this version throws an error "Cannot read property 'getAttribute' of undefined". But, I can't find where it deviates from the documentation:
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2019 09:32 PM
Hi,
Instead of calling initialize function call say XYZ, for example:
Script include:
var prettydiffSN = Class.create();
prettydiffSN.prototype = Object.extendsObject(AbstractAjaxProcessor, {
XYZ: function (){
var result = this.newItem("result");
result.setAttribute("message", "The great payload");
},
type: 'prettydiffSN'
});
Client script:
function onLoad() {
var ajax = new GlideAjax('global.prettydiffSN');
ajax.addParam('sysparm_name', "XYZ");
ajax.getXML(getDiffCode);
function getDiffCode(response) {
var doc = response.responseXML.getElementsByTagName("result");
var message = doc[0].getAttribute("message");
jslog(message);
alert(message);
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2019 07:50 PM
When you want to call a script include function asynchronously from a client script or other client-side code, the function needs to return a value:
initialize: function() {
var result = this.newItem("result");
result.setAttribute("message", "The great payload");
return result;
},
In the client code the value returned can be retrieved by calling the responseXml.documentElement.getAttribute("answer") method:
var ajax = new GlideAjax('global.prettydiffSN');
ajax.addParam('sysparm_name', "initialize");
ajax.getXML(getDiffCode);
function getDiffCode(response) {
var doc = response.responseXML.documentElement.getAttribute("answer");
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2019 10:44 AM
It turns out, your approach is the simplest (most proper?) way to do this. However, I was shadowing the "initialize" function. After I fixed that, the tag/attribute, "result"/"message", were present along with the returned value you suggested.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2019 09:32 PM
Hi,
Instead of calling initialize function call say XYZ, for example:
Script include:
var prettydiffSN = Class.create();
prettydiffSN.prototype = Object.extendsObject(AbstractAjaxProcessor, {
XYZ: function (){
var result = this.newItem("result");
result.setAttribute("message", "The great payload");
},
type: 'prettydiffSN'
});
Client script:
function onLoad() {
var ajax = new GlideAjax('global.prettydiffSN');
ajax.addParam('sysparm_name', "XYZ");
ajax.getXML(getDiffCode);
function getDiffCode(response) {
var doc = response.responseXML.getElementsByTagName("result");
var message = doc[0].getAttribute("message");
jslog(message);
alert(message);
}
}