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
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
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
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
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);
}