Can any one explain how to call script include from business rule. please explain the differences between ondemand /classless , extend an exising class and define a new class.

Kalpana10
Giga Contributor

Hi All,

 

 

Can any one explain how to call script include from business rule. please explain the differences between ondemand /classless , extend an exising class  and define a new class.

1 ACCEPTED SOLUTION

Sudhanshu Talw1
Tera Guru

Script Includes are ondemand reusable server side code. 

Class based where you define something like this:

var NewInclude =Class.create();
 
NewInclude.prototype={
   initialize :function(){},
 
   myFunction :function(){//Put function code here},
 
   type :'NewInclude'};

Call this in your BR as:
var foo =new NewInclude();
foo.myFunction();

Classless: is basically you create when your SI has only single function in case of mutplie functions in your SI you should define Class full.

For calling SI via client script you should use GlideAjax API.

View solution in original post

5 REPLIES 5

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Pratiksha Kalam
Kilo Sage

Hello,

In BR,

    var si = new MyScriptInclude();

    si.myMethod();

   

Script Includes are reusable server-side script logic that define a function or class. Script Includes execute their script logic only when explicitly called by other scripts. There are different types of Script Includes:

  • On demand/classless
  • Extend an existing class
  • Define a new class

For more information, Click here

 

If answer is helpful please mark correct!

Thanks,

Pratiksha

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Kalpana,

sharing few links for help; they should definitely guide you in right direction

https://www.basicoservicenowlearning.in/2019/12/script-include-servicenow.html

https://developer.servicenow.com/dev_app.do#!/lp/new_to_servicenow/app_store_learnv2_scripting_orlan...

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Megha Padale
Giga Guru

Hi Kalpana,

Adding to Pratiksha, There are basically 3 types of Script Includes in  ServiceNow.

1) Client-Callable Script Include( Classless): Classless Script Includes will generally contain a single function definition, as shown below for the function getMyTitle(). However it is possible to define multiple functions within the same Script Include.find_real_file.png

 

2) Script Include with class : 

Defining a Script Include with a Class may seem more complex at first, but ServiceNow actually provides the initial code stub upon naming the record. Shown below is a basic Classdefinition.

find_real_file.png

 

3) On Demand Script Include : A Script Include that defines a single function is known as an on demand, or classless, Script Include. The function is callable from other server-side scripts. On demand Script Includes can never be used client-side even if the Client callable option is selected.

It is critical that the Script Include name is an exact match for the name of the function. In the example, both the Script Include and the function are named sumTwoNums.

find_real_file.png

If my answer helped you in any way, mark answer as helpful and correct.

Thanks and regards,

Megha.