Help Required with Script Include and associated client script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2023 09:41 AM
To show 'Special Handling Notes' as a pop-up message on changing a company field on the incident table, we have developed a UI Page, Script Include, and Client Script. I need to get my scripts running on two cases. Case 1 worked, but I was unable to get Case 2 to work. Would someone please assist?
Case 1: The scripts works well when the Special Handling Notes are on the 'Company' table and when the incident form's company value is modified to a different value.
Case 2: I also want it to work when the value of company changes and there is a "Type -2" Special Handling Notes on the Incident table with a condition pertaining to that specific company. In this scenario, I want the pop-up to appear.
Script Include
var Special_Handling_Notes_Popup_on_Case = Class.create();
Special_Handling_Notes_Popup_on_Case.prototype = Object.extendsObject(AbstractAjaxProcessor, {
ReturnNotes: function(tableName, id) {
var notes = [];
//For Conditional Type Special Handling Notes
var con = new GlideRecord('sn_shn_notes');
con.addEncodedQuery('type=2^status=1');
con.query();
while (con.next()) {
var table = con.getValue('table_name');
var condition = con.getValue('conditions');
if (table == tableName) {
var gr = new GlideRecord(tableName);
gr.addEncodedQuery(con.getValue('conditions'));
gr.query();
while (gr.next()) {
if (gr.sys_id == id) {
notes.push(con.getValue('sys_id'));
}
}
}
}
//For Standard Type Special Handling Notes
var get_notes = new GlideRecord('sn_shn_notes');
get_notes.addQuery('related_record', id.toString());
get_notes.addQuery('table_name', tableName.toString());
get_notes.addQuery('status', '1');
get_notes.query();
while (get_notes.next()) {
notes.push(get_notes.getValue('sys_id'));
}
return notes;
},
ReturnNotesSI: function() {
var notes = [];
/********* For Conditional Type Special Handling Notes ************/
var tableName = this.getParameter('sysparm_table');
var id = this.getParameter('sysparm_id');
var con = new GlideRecord('sn_shn_notes');
con.addEncodedQuery('type=2^status=1');
con.query();
while (con.next()) {
var table = con.getValue('table_name');
var condition = con.getValue('conditions');
if (table == tableName) {
var gr = new GlideRecord(tableName);
gr.addEncodedQuery(con.getValue('conditions'));
gr.query();
while (gr.next()) {
if (gr.sys_id == id) {
notes.push(con.getValue('sys_id'));
}
}
}
}
/********* For Standard Type Special Handling Notes ************/
var get_notes = new GlideRecord('sn_shn_notes');
get_notes.addQuery('related_record', id.toString());
get_notes.addQuery('table_name', tableName.toString());
get_notes.addQuery('status', '1');
get_notes.query();
while (get_notes.next()) {
notes.push(get_notes.getValue('sys_id'));
}
this.getRootElement().setAttribute('AnswerNotes', notes);
},
type: 'Special_Handling_Notes_Popup_on_Case'
});
Client Script for case 1
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var tableName = 'core_company';
var id = newValue;
var gm = new GlideModal('special_handling_notes_onchange');
gm.setTitle(getMessage('Special Handling Notes'));
gm.setWidth("$[width]");
gm.setPreference("tableName", 'core_company');
gm.setPreference("id", g_form.getValue('company'));
gm.setPreference("focusTrap", true);
var ga = new GlideAjax('Special_Handling_Notes_Popup_on_Case');
ga.addParam('sysparm_name', 'ReturnNotesSI');
ga.addParam('sysparm_table', tableName);
ga.addParam('sysparm_id', id);
ga.getXML(Callback);
function Callback(response) {
var answer = response.responseXML.documentElement.getAttribute('AnswerNotes');
if (answer != '') {
gm.render();
}
}
}