How to override initialize function in OOTB script include
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-12-2023 07:40 AM
Hello all,
I am trying to override the "initialize" method in an OOTB script include but I'm not sure how to how to do this. For example, I'm trying to change the "EMPLOYEE_TAXONOMY" variable in the "EmployeeTaxonomyUtilSNC" script include below:
var EmployeeTaxonomyUtilSNC = Class.create();
EmployeeTaxonomyUtilSNC.prototype = {
initialize: function() {
this.EMPLOYEE_TAXONOMY = '1f5d5a40c3203010069aec4b7d40dd93';
},
/**
* This function deactivates and activates and all the topics of 'Employee' which in turn updates the primary topic field ('taxonomy_topic') for all the content assoicated to this taxonomy. This step is required to make Search configurations work with OOTB Employee taxonomy.
**/
toggleTopicsActiveState: function() {
if (!gs.hasRole('taxonomy_admin')) {
gs.info(gs.getMessage("User {0} does not have write access to the given taxonomy and its topic", [gs.getUserID()]));
return;
}
var topicGr = new GlideRecord('topic');
topicGr.addQuery('taxonomy', this.EMPLOYEE_TAXONOMY);
topicGr.addActiveQuery();
topicGr.query();
while (topicGr.next()) {
topicGr.setValue('active', false);
topicGr.update();
topicGr.setValue('active', true);
topicGr.update();
}
},
type: 'EmployeeTaxonomyUtilSNC'
};
Since this is an OOTB script include, I need to override the method from the "EmployeeTaxonomyUtil" script include. How can I override the "EMPLOYEE_TAXONOMY" variable from the script below?
var EmployeeTaxonomyUtil = Class.create();
EmployeeTaxonomyUtil.prototype = Object.extendsObject(EmployeeTaxonomyUtilSNC, {
initialize: function() {
EmployeeTaxonomyUtilSNC.prototype.initialize.apply(this, arguments);
},
type: 'EmployeeTaxonomyUtil'
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2023 11:47 AM
Hello,
In order to override the "EMPLOYEE_TAXONOMY" variable from the 'EmployeeTaxonomyUtilSNC' script include:
- Create a new script include based on the existing one ('EmployeeTaxonomyUtil')
- Edit the initialize function and add the sys_id of your taxonomy:
var MyEmployeeTaxonomyUtil = Class.create();
MyEmployeeTaxonomyUtil.prototype = Object.extendsObject(EmployeeTaxonomyUtilSNC, {
initialize: function() {
EmployeeTaxonomyUtilSNC.prototype.initialize.apply(this, arguments);
this.EMPLOYEE_TAXONOMY = 'Insert your taxonomy sys_id here';
},
type: 'MyEmployeeTaxonomyUtil'
});
3. Create a new fix script based on the existing one ('Set primary topics for Employee taxonomy') and call your new script include.
var employeeUtil = new sn_ect.MyEmployeeTaxonomyUtil();
employeeUtil.toggleTopicsActiveState();
Related articles:
https://noderegister.service-now.com/kb?id=kb_article_view&sysparm_article=KB1212940
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2023 02:37 PM - edited 10-24-2023 03:26 PM