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

sivaiah
Kilo Contributor

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

2 REPLIES 2

Dan H
Tera Guru

HI,

 

Parent/Base class

find_real_file.png

 

Script: 

var scriptIncludeBase = Class.create();
scriptIncludeBase.prototype = {
    initialize: function() {
    },
	
	upperCase : function(string){
		return string.toUpperCase();
	},

    type: 'scriptIncludeBase'
};

 

Child class/extended class

find_real_file.png

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

shloke04
Kilo Patron

Hi @sivaiah 

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:

find_real_file.png

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:

find_real_file.png

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

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke