gs.include() versus new ScriptInclude()

kungfuu72
Giga Expert

Came across a few examples where out-of-box code may reference gs.include('ScriptInclude');

But then what would be the difference (if any) in using

gs.include('ScriptInclude');

versus

var foo = new NewInclude();

I'm curious as to the differences and/or the advantages.

1 ACCEPTED SOLUTION

harikrish_v
Mega Guru

Hi Daniel,



gs.include() allows you to call a script include and use the functions in that script include within your current script include i.e you do not have to copy the functions into your current script include, but rather you can call them directly.



var foo = new NewInclude() initializes an object for the script include NewInclude. Now any function that you have defined within this script include class can be called directly using foo:-




eg:-




var NewInclude = Class.create();


NewInclude.prototype = {


  initialize : function() {


  },


      myFunction : function() {


          //do something


  },



  type : 'NewInclude'


};


Usage:-


var foo = new NewInclude();


foo.myFunction();


Thanks & Regards,


Hari




View solution in original post

5 REPLIES 5

darshanr
Kilo Guru

Hi Daniel,


  1. gs.include('ScriptInclude') is mainly used in Script Includes where you want to use the methods of that script include directly in current Script Include.
  2. So that there is no need to rewrite the same function in this SI.

harikrish_v
Mega Guru

Hi Daniel,



gs.include() allows you to call a script include and use the functions in that script include within your current script include i.e you do not have to copy the functions into your current script include, but rather you can call them directly.



var foo = new NewInclude() initializes an object for the script include NewInclude. Now any function that you have defined within this script include class can be called directly using foo:-




eg:-




var NewInclude = Class.create();


NewInclude.prototype = {


  initialize : function() {


  },


      myFunction : function() {


          //do something


  },



  type : 'NewInclude'


};


Usage:-


var foo = new NewInclude();


foo.myFunction();


Thanks & Regards,


Hari




Hi Harikrishnan,


I have a little doubt here.


So in my script include, i can use other script include's method, without instantiating the script include class, using gs.include(). is that it?



Regards,


Swarnadeep Nandy


Runjay Patel
Giga Sage

Check out this video, it will clear all your doubts and help you to understand Script Include And Ajax Call queries in details.

Link: https://www.youtube.com/watch?v=qNiYWMMzC2o&t=209s&ab_channel=ServiceNowHelpdesk

It help you to understand below points.

 

  • Understand Script Include And Ajax Call
  • When, How and in which scenario we will use it.
  • Understand Synchronous (getXMLWait()) and aSysnchronous (getXML()) Ajax call and scenario based use of it.

 

Please mark reply as Helpful/Correct, if applicable. Thanks!!