How to call Script Include from another Script Include?

Sarah Bouil
Tera Expert

How to call Script Include from another Script Include?

 

AND

 

how to call functions/methods from one Script Include to another Script Include functions/methods?

1 REPLY 1

Samaksh Wani
Giga Sage
Giga Sage

Hello @Sarah Bouil 

In ServiceNow, Script Includes are reusable server-side JavaScript objects that can be used to store and share functions. To call one Script Include from another, you can follow these steps:

Let's assume you have two Script Includes:



Script Include A:

var ScriptIncludeA = Class.create();
ScriptIncludeA.prototype = {
   initialize: function() {},

   someFunctionA: function() {
      // Your code here
   },

   // other functions in Script Include A
};


Script Include B:
var ScriptIncludeB = Class.create();
ScriptIncludeB.prototype = {
   initialize: function() {},

   someFunctionB: function() {
      // Call function from Script Include A
      var scriptIncludeA = new ScriptIncludeA();
      scriptIncludeA.someFunctionA();
   },

   // other functions in Script Include B
};


Please mark the response as Accepted, if you find it helpful.

 

Regards,

Samaksh Wani