- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2024 04:32 AM
Hi All,
What is the best way to use the function from base script include into extended script include. Can I call that function using this keyword or not.
Thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2024 05:04 AM
Hi @Obito ,
The best way to use a function from a base Script Include in an extended Script Include is to ensure that the base Script Include is set to be accessible (i.e., it's not private). You can call the function using the this keyword within the extended Script Include, as it refers to the current instance of the Script Include.
Here's how to do it:
Ensure Base Script Include is Public: Make sure the base Script Include has the appropriate access settings (public or protected).
Inherit the Base Script Include: In your extended Script Include, inherit from the base Script Include by specifying the name of the base Script Include in the "Extends" field.
Call the Function: Use this.functionName() to call the function from the base Script Include within the extended Script Include.
Example
Base Script Include (BaseScriptInclude):
var BaseScriptInclude = Class.create();
BaseScriptInclude.prototype = {
initialize: function() {
},
myFunction: function() {
return "Hello from Base Script Include!";
},
type: 'BaseScriptInclude'
};
Extended Script Include (ExtendedScriptInclude):
var ExtendedScriptInclude = Class.create();
ExtendedScriptInclude.prototype = Object.extendsObject(BaseScriptInclude, {
initialize: function() {
},
callBaseFunction: function() {
return this.myFunction(); // Calling the function from the base script include
},
type: 'ExtendedScriptInclude'
});
This approach allows you to effectively reuse and extend functionality from base Script Includes in your ServiceNow environment.
Hope this help you.
Regards
Moin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2024 05:04 AM
Hi @Obito ,
The best way to use a function from a base Script Include in an extended Script Include is to ensure that the base Script Include is set to be accessible (i.e., it's not private). You can call the function using the this keyword within the extended Script Include, as it refers to the current instance of the Script Include.
Here's how to do it:
Ensure Base Script Include is Public: Make sure the base Script Include has the appropriate access settings (public or protected).
Inherit the Base Script Include: In your extended Script Include, inherit from the base Script Include by specifying the name of the base Script Include in the "Extends" field.
Call the Function: Use this.functionName() to call the function from the base Script Include within the extended Script Include.
Example
Base Script Include (BaseScriptInclude):
var BaseScriptInclude = Class.create();
BaseScriptInclude.prototype = {
initialize: function() {
},
myFunction: function() {
return "Hello from Base Script Include!";
},
type: 'BaseScriptInclude'
};
Extended Script Include (ExtendedScriptInclude):
var ExtendedScriptInclude = Class.create();
ExtendedScriptInclude.prototype = Object.extendsObject(BaseScriptInclude, {
initialize: function() {
},
callBaseFunction: function() {
return this.myFunction(); // Calling the function from the base script include
},
type: 'ExtendedScriptInclude'
});
This approach allows you to effectively reuse and extend functionality from base Script Includes in your ServiceNow environment.
Hope this help you.
Regards
Moin