Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Script Include Function Not Being Called

fcaruso123
Tera Expert

I am using the following script on a UI Action:

 

function SimpleTest() {
    var a = new GlideAjax('FrankNewInclude');
    a.addParam('sysparm_name', 'test');
    a.getXML(myCallBack);
}

function myCallBack(response) {
    alert(response);
    var answer = response.responseXML.documentElement.getAttribute("document");
    alert(answer);
}

 

Using the following include:

 

var FrankNewInclude = Class.create();
FrankNewInclude.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    initialize: function() {
        gs.log('Frank - Initialize');
    },
    test: function() {
        gs.log('Frank - myFunction: ');
        return true;
    },
    type: 'FrankNewInclude'
});

 

I can see a log message being fired when the object is instantiated but the "test" function is never called.

However, if I remove the "initialize" function then the "test" function works.

 

Can anyone explain why?

 

Thank you.

1 ACCEPTED SOLUTION

-O-
Kilo Patron

Your GlideAjax end-point Script Include must not contain an initialize methos.

Or if it does contain one, it must call the base initialize method with the right parameters in the right context:

 

initialize: function(request, responseXML, gc) {
	AbstractAjaxProcessor.prototype.initialize.call(this, request, responseXML, gc);
	gs.log('Frank - Initialize');
},

 

View solution in original post

3 REPLIES 3

swathisarang98
Giga Sage

Hi @fcaruso123 ,

 

Have checked true for client in UI action and in  Onclick have you called the function SimpleTest() ?

and also use gs.info to get logs 

 

Please mark this comment as Correct Answer/Helpful if it helped you.

Regards,

Swathi Sarang

-O-
Kilo Patron

Your GlideAjax end-point Script Include must not contain an initialize methos.

Or if it does contain one, it must call the base initialize method with the right parameters in the right context:

 

initialize: function(request, responseXML, gc) {
	AbstractAjaxProcessor.prototype.initialize.call(this, request, responseXML, gc);
	gs.log('Frank - Initialize');
},

 

-O-
Kilo Patron

Also, do yourself a favor and use getXMLAnswer (vs. getXML); if you do you can loose all the:

 

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

 

crap and just need:

 

function myCallBack(answer) {
	alert(answer);
}