The CreatorCon Call for Content is officially open! Get started here.

how to write the Script include in service now

anilkumarsharma
Giga Guru

Hi Team,

i have wriiten bellow mention Script include   but when   i go to in Script include and paste the same then click on check then i got the error (ERROR at line 1: Expected an assignment or function call and instead saw an expression) Pls. Suggest

Var newinclude = Class.create();

  1. newinclude.prototype= {

Initialize : function(){

},

myFunction:function()

{

var t = gs.getUserID();

  1. gs.print("Print the value:" +t);

}

type: 'newinclude'

};

9 REPLIES 9

could you please mark it as correct answer if it solves the issue.


bernyalvarado
Mega Sage

Hi Anil, just for documentation purposes. A script include can also be classless. The name of the script include would just need to be the same as the one of the function. The OOB getTableExtensions script include is a good example:



script include name: getTableExtensions



function getTableExtensions(objectName) {


      var list = GlideDBObjectManager.get().getTableExtensions(objectName);


      list.add(objectName);


      return list;


}



I hope you find this helpful!



Thanks,


Berny


Poonam22
Giga Contributor

Hi,

On your question how to create script includes:

Navigate to System Definition > Script includes > New

Type the 'Name' of the script include function which would populate the 'Script' block with the following :

Note: In my case I have given the name of script include as script.

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

type: 'script'
};

 

Click the Client Callable tick-box, and the script field will change again. The first line declares your script include as a new class. The second line sets the prototype so that your script include extends another script include, called AbstractAjaxProcessor. This is because AbstractAjaxProcessor already has most of the methods and properties that we're going to need. It makes our job easier! 

This is what I see in my case :

var script = Class.create();
script.prototype = Object.extendsObject(AbstractAjaxProcessor, {

type: 'script'
});

 

When developing scripts for scoped applications, you must use the scoped APIs, which include scoped versions of the Glide APIs. The scoped Glide APIs do not provide all the methods included in the global Glide APIs, and you cannot call a global GlideAPI in a scoped application.

 

Behshid Khairdi
Mega Expert

Hi anilkumarsharma,

 

The error you are getting at line 1 is because the 'Var' should actually be 'var' and also you don't need to take a.newInclude.prototype, just newinclude.prototype.

 

Buddy2
Giga Contributor

Hi, 

You will get the complete understanding of script include with practical example in below link:

 

Script Include in ServiceNow

 

Please mark my answer correct and helpful if my answer helped u. Thank you.