Overriding Script Include: Question?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2024 05:26 AM
Hey Everyone,
I learned that you can override ServiceNow's read only script includes by extending using the Object.extendsObjext.
Below is the editable script include. I thought if I copied and pasted the function that I wanted to override in MIMWorkbenchUtilSNC, it would override, but it isn't. What am I missing?
The code from the read only script include.
Has anyone tried this? Please let me know.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2024 06:09 AM
In the out of the box script include, it is initialized by AbstractAjaxProcessor
initialize: function(request, responseXML, gc) {
AbstractAjaxProcessor.prototype.initialize.call(this, request, responseXML, gc);
},
After that it declares several variables within a function.
addChildTasks: function() {
var taskSysId = this.getParameter("sysparm_sys_id");
var table = this.getParameter("sysparm_table");
var selectedTasks = this.getParameter("sysparm_selected_tasks");
var query = this.getParameter("sysparm_query");
var parentColumn = this.getParameter("sysparm_parent_column");
var type = this.getParameter("sysparm_type");
if (!taskSysId) {
gs.log("[addChildTasks] Invalid Parameter - sysparm_sys_id is empty or null");
return;
}
if (!table) {
gs.log("[addChildTasks] Invalid Parameter - sysparm_table is empty or null");
return;
}
if (!parentColumn) {
gs.log("[addChildTasks] Invalid Parameter - sysparm_parent_column is empty or null");
return;
}
So, why isn't the script include that I created doesn't override it?
I literally just copied and pasted the below function to the new script include, but when I change the requiredFields variable values it doesn't change in the UI Page. Not sure what else I need to do here.
getTaskDetails: function(table, sys_id) {
var requiredFields = ['number', 'sys_class_name', 'state', 'major_incident_state', 'sys_created_on', 'short_description', 'assigned_to', 'priority', 'category', 'description', 'close_code', 'close_notes', 'resolved_at', 'overview', 'lessons_learned', 'timeline', 'closed_at', 'active', 'problem_id', 'rfc', 'caused_by', 'cmdb_ci'];
var gr = new GlideRecord(table);
if(gr.get(sys_id)) {
return {
taskJs: this.toJS(gr, requiredFields),
taskGr: gr
};
}
},