Extend a Script Include for ex ABC in a new Script Include and show how can you use a function existing in ABC inside a function of new Script Include
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-04-2022 11:30 PM
Extend a Script Include for ex ABC in a new Script Include and show how can you use a function existing in ABC inside a function of new Script Include
- Labels:
-
Incident Management

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-05-2022 02:17 AM
HI,
Parent/Base class
Script:
var scriptIncludeBase = Class.create();
scriptIncludeBase.prototype = {
initialize: function() {
},
upperCase : function(string){
return string.toUpperCase();
},
type: 'scriptIncludeBase'
};
Child class/extended class
Script:
var scriptIncludeExtend = Class.create();
scriptIncludeExtend.prototype = Object.extendsObject(scriptIncludeBase,{
callParent: function(string) {
return this.upperCase(string);
},
type: 'scriptIncludeExtend'
});
Usage: in background script:
var result = new scriptIncludeExtend().callParent('servicenow');
gs.log(result);
Result: SERVICENOW
Notice that the extended script include has:
Object.extendsObject(scriptIncludeBase
This extends the parent class and allows you to access it's functions using the this keyword
Please mark my answer as Correct/Helpful based on impact
Regards,
Dan H
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-05-2022 04:36 AM
Hi
To understand this in simple terms, let us consider an example to make you understand as below:
1) Say you have a Parent Script Include named "ParentSI". Now within this Script Include you have a function named "parentFunction" as shown below:
Now if you want to extend any of the method defined in parent Script Include, then you just need to create another Script Include exactly similar syntax as shown below and just call the same Method Name which is present in Parent Script Include as shown below:
var childSI = Class.create();
childSI.prototype = Object.extendsObject(ParentSI,{
initialize: function() {
},
parentFunction:function(){
},
type: 'childSI'
});
Screenshot with highlighted in Red will explain different component which are used in script above while extending the parent script include:
Now just call the child Script include in either Server or Client side script as you need.
There is a video as well on this to demonstrate this:
https://community.servicenow.com/community?id=community_video&sys_id=7efedb96db5e2490f21f5583ca9619d9
https://developer.servicenow.com/dev.do#!/learn/courses/quebec/app_store_learnv2_scripting_quebec_scripting_in_servicenow/app_store_learnv2_scripting_quebec_server_side_scripting/app_store_learnv2_scripting_quebec_extend_a_script_include
Hope this helps. Please mark the answer as correct/helpful based on impact.
Regards,
Shloke
Regards,
Shloke