- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2022 10:57 AM
So I realize that using an initialize function on a GlideAjax is a bad thing to do.
On regular script includes, I use the initialize function to declare certain variables that will be used by the class. Is there any way to do this on a GlideAjax script include if the initialize function cannot be used?
Thanks
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2022 11:38 AM
Hi,
Additional example in this article here: https://community.servicenow.com/community?id=community_article&sys_id=1f0f6af11be7cd14c552c8031d4bc...
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
08-18-2022 11:12 AM
Yes, however you need to add some extra bits to make the Client Callable part still work.
I have this in my "template" when I make a GlideAjax.
var SomeUtil = Class.create();
SomeUtil.prototype = Object.extendsObject(AbstractAjaxProcessor, {
// If you want to use initialize you can only if you include
// AbstractAjaxProcessor with something like this;
/*
initialize: function(request, responseXML, gc) {
global.AbstractAjaxProcessor.prototype.initialize.call(this, request, responseXML, gc);
// Your code
},
*/
awesomeFunction: function(){
var inputObj = JSON.parse(this.getParameter('sysparm_obj'));
var returnObj = {
from:"server",
input: inputObj
};
return JSON.stringify(returnObj);
},
type: 'SomeUtil'
});
Client Callable script includes extend the AbstractAjaxProcessor, so overwriting any of the methods in there like initialize or getName will cause problems.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2022 11:30 AM
Are you suggesting that the initialize in your example needs to be declared as an extension of the AbstractAjaxProcessor initialize function? And this will allow for this.<variableName> declarations?
Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-20-2022 08:14 PM
I'm suggesting that if you want a method called initialize and you want this to still work you'll need to also add that additional line to it.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2022 11:38 AM
Hi,
Additional example in this article here: https://community.servicenow.com/community?id=community_article&sys_id=1f0f6af11be7cd14c552c8031d4bc...
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!