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.

Adding initialize script include is not callable from client

thisisauniqueus
Giga Expert

Hi

I have a script include like

var Util = Class.create();

Util.prototype = Object.extendsObject(AbstractAjaxProcessor, {

     

ExampleFunc: function(curr) {

  }

.....

i wanted to call it from server side as well as from client so initialized it like

var Util = Class.create();

Util.prototype = Object.extendsObject(AbstractAjaxProcessor, {

initialize: function() {   },

ExampleFunc: function(curr) {

  }

.....

but when i add initialize: function() {   },   i am unable to call the function from the client script and if i remove it its not callable form server

pl help!

Regards

6 REPLIES 6

ramireddy
Mega Guru

Hi,



If you want to make a script "Client callable", you can't have "initialize" function. This syntax works both using server and client.



var Util = Class.create();


Util.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {


ExampleFunc: function(curr) {


  },


});


something is telling me that its not a good idea i tend to avoid global sort of inclusions your comments?


A workaround is to add a custom method, for example _init().


You can then call it after your script include. Example:



var TestCL = Class.create();


TestCL.prototype = Object.extendsObject(AbstractAjaxProcessor, {



  _init: function() {


  this.test = "initialized value";


  },



  run: function() {


  return this.test;


  },



      type: 'TestCL'


});




TestCL.prototype._init();


ramireddy
Mega Guru

Considering the new apps are mostly "scoped applications",   there are chances that a new script include can be created with same name under different scope. So, to avoid ambiguity, its advisable to use "global".



Thanks


Rami Reddy