- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-18-2018 03:15 AM
Dear Friends,
We have 2 script includes GRCUtils and GRCUtilsBase. GRCUtilsBase is a Servicenow base class script include and hence is not editable. It has all the functions and code. I want to update a function. So I was overriding that function in GRCUtils which extends the base class. Now when I override then the code does not work. I copied the same code in GRCUtils just for testing purposes but it didn't work. Could you pleas help? Please tell if I am overriding it correctly or not
var GRCUtils = Class.create();
GRCUtils.prototype = Object.extendsObject(GRCUtilsBase, {
//Override base class function
generateProfilesFromType: function(type, updateClassIfExists) { --> updateClassIfExists is function in base class
return this._generateProfilesFromType(type, updateClassIfExists); },
_generateProfilesFromType: function(typeQuery) {
gs.log('++start');
var results = {
added: 0,
----
---
--
return results; },
type: 'GRCUtils'
});
Regards
Ramandeep
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
-
Team Development
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-18-2018 04:22 AM
Sorry Ramandeep,
forgot to copy paste the output indeed
Output:
*** Script: Employeee log
*** Script: Consultant log
*** Script: Base function called!
Stijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-18-2018 03:51 AM
Hi Ramandeep,
I have a concrete example for you:
var Employee = Class.create();
Employee.prototype = {
initialize: function() {
},
baseClassFunction: function() {
gs.log('Base function called!');
},
printLog: function() {
gs.log('Employeee log');
},
type: 'Employee'
};
};
var Consultant = Class.create();
Consultant.prototype = Object.extendsObject(Employee, {
printLog: function() {
gs.log('Consultant log');
this.baseClassFunction();
},
type: 'Consultant'
});
});
With the following statements run via Scripts - Background I retrieve the following result as expected due to overriding:
new Employee().printLog();
new Consultant().printLog();
Hope this helps you.
Kind regards,
Stijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-18-2018 04:11 AM
Hi Stijn,
Thank you for looking into it! Could you please share the output after running the script statements? I think you missed output in your last reply.
Regards
Ramandeep
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-18-2018 04:22 AM
Sorry Ramandeep,
forgot to copy paste the output indeed
Output:
*** Script: Employeee log
*** Script: Consultant log
*** Script: Base function called!
Stijn