how to write the Script include in service now
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-17-2015 03:55 AM
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();
- newinclude.prototype= {
Initialize : function(){
},
myFunction:function()
{
var t = gs.getUserID();
- gs.print("Print the value:" +t);
}
type: 'newinclude'
};
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-17-2015 07:50 AM
could you please mark it as correct answer if it solves the issue.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-17-2015 08:01 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2018 11:53 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2018 12:13 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-28-2019 06:57 AM
Hi,
You will get the complete understanding of script include with practical example in below link:
Please mark my answer correct and helpful if my answer helped u. Thank you.