Why can't I access method in Script Include

dalton1
Giga Expert

Hi,

I have a script include and catalog client script that instantiates and access the script include. Problem is, it does not return the value.

Script Include

==========

var acn_catalogClientScripts = Class.create();

acn_catalogClientScripts.prototype = {

      initialize: function() {

            this.errorMessage = "";

      },

  sampleFunction: function(){

  return "SampleAnswer!";

  },

      type: 'acn_catalogClientScripts'

};

Catalog client script

=================

var validation = new gacn_catalogClientScripts();

var validation_result = validation.sampleFunction();

g_form.addErrorMessage("Value is " + validation_result);

validation_result does not return anything. Please help. Do I really have to use GlidAjax for this? As per my understanding, accessing script include can be done this way.

1 ACCEPTED SOLUTION

All i know is initialize is the function coming from super class and they mentioned on wiki like


  • Avoid overriding methods of AbstractAjaxProcessor, including initialize. While it is possible to invoke methods of your superclass object which you have overridden, it is complicated and best avoided altogether.

GlideAjax - ServiceNow Wiki


View solution in original post

15 REPLIES 15

my script include is already client callable. See below screenshot:



script_include1.PNG


What other things do I need to check?


Hi Gurpreet Singh,



I have noticed that when I have removed initialize function in my script include. It suddenly works!



From


========


acn_catalogClientScripts.prototype = Object.extendsObject(AbstractAjaxProcessor, {


      initialize: function() {


            this.errorMessage = "";


      },


  sampleFunction: function(){


  return "SampleAnswer!";


  },


      type: 'acn_catalogClientScripts'


});




To


========


acn_catalogClientScripts.prototype = Object.extendsObject(AbstractAjaxProcessor, {



  sampleFunction: function(){


  return "SampleAnswer!";


  },


      type: 'acn_catalogClientScripts'


});



Output:


========


"Answer is SampleAnswer!"




Why can't I have initialize function in script include?


Ok good .   Now again try to add initialize function in script include and test it again   .. it should work .


Hi Gurpreet Singh



Below is my updated script include:



var acn_catalogClientScripts_abstractAjax = Class.create();


acn_catalogClientScripts_abstractAjax.prototype = Object.extendsObject(AbstractAjaxProcessor, {


      initialize: function() {


  this.errorMessage = "";


      },


  sampleFunction: function(){


  this.errorMessage = "NewSampleAnswer!";


  return this.errorMessage;


  },


      type: 'acn_catalogClientScripts_abstractAjax'


});



Output


=====



"Answer is null"



I keep on getting null whenever I add the initialize function. If i remove it, it works perfectly. What am I doing wrong?


All i know is initialize is the function coming from super class and they mentioned on wiki like


  • Avoid overriding methods of AbstractAjaxProcessor, including initialize. While it is possible to invoke methods of your superclass object which you have overridden, it is complicated and best avoided altogether.

GlideAjax - ServiceNow Wiki