Name
sn_sow_walkup.WalkupInteractionInfoSNC
Description
No description available
Script
var WalkupInteractionInfoSNC = Class.create();
WalkupInteractionInfoSNC.prototype = {
TABLES: {
APPOINTMENT: 'wu_appointment',
INTERACTION_RELATED_RECORD: 'interaction_related_record'
},
FIELD_DETAILS: {
'priority': {
'type': 'highlighted-value',
'color_map': {
'1': 'critical',
'2': 'high',
'3': 'info',
'4': 'moderate',
'5': 'low'
},
'empty_value': gs.getMessage("Unknown")
},
'assigned_to': {
'type': 'string',
'empty_value': gs.getMessage("Not assigned")
},
'default': {
'type': 'string',
'empty_value': gs.getMessage("(empty)")
}
},
initialize: function(gr) {
this._gr = gr;
this._grSysId = gr.getUniqueValue().toString();
this._contextGr = null;
this._appointmentGr = null;
this._sourceIncidentGr = null;
},
_getFieldsInfo: function(gr, fields) {
var result = [];
for (var i = 0; i < fields.length; i++) {
var field = fields[i];
var value = gr.getDisplayValue(field);
var item = {};
item.label = gr[field].getLabel();
item.value = {};
var fieldInfo = this.FIELD_DETAILS[field] ? this.FIELD_DETAILS[field] : this.FIELD_DETAILS['default'];
item.value.type = fieldInfo['type'];
if (item.value.type == 'highlighted-value') {
item.value.label = value || fieldInfo['empty_value'];
item.value.status = this.FIELD_DETAILS[field]['color_map'][gr.getValue(field)];
} else {
item.value.value = value || fieldInfo['empty_value'];
}
result.push(item);
}
return result;
},
_loadContextGr: function() {
var gr = new GlideRecord(this._gr.getValue("context_table"));
var documentId = this._gr.getValue("context_document");
if (documentId && gr.get(documentId)) {
this._contextGr = gr;
}
},
_loadAppointmentGr: function() {
var gr = new GlideRecord(this.TABLES.APPOINTMENT);
gr.addQuery("interaction", this._gr.getValue('sys_id'));
gr.orderByDesc("sys_created_on");
gr.query();
if (gr.next()) {
this._appointmentGr = gr;
}
},
_loadSourceIncidentGr: function() {
var gr = new GlideRecord(this.TABLES.INTERACTION_RELATED_RECORD);
gr.addQuery('interaction', this._grSysId);
gr.addQuery('document_table', 'incident');
gr.orderByDesc('sys_created_on');
gr.setLimit(1);
gr.query();
if (gr.next()) {
this._sourceIncidentGr = gr;
}
},
getRecordInfo: function() {
// Load related info
this._loadContextGr();
this._loadAppointmentGr();
this._loadSourceIncidentGr();
var result = {};
result.headerInfo = this.getHeaderInfo();
result.openedForInfo = this.getOpenedForInfo();
result.contextInfo = this.getContextInfo();
result.appointmentInfo = this.getAppointmentInfo();
result.sourceIncidentInfo = this.getSourceIncidentInfo();
return result;
},
getHeaderInfo: function() {
var result = {};
result.mainHeading = gs.getMessage('Record Information');
result.updateMsg = gs.getMessage("Last updated by {0}", this._gr.getDisplayValue('sys_updated_by'));
result.updatedTime = this._gr.sys_updated_on.getDisplayValue();
result.openedForHeading = gs.getMessage('Opened for');
result.sourceHeading = gs.getMessage('Source');
result.startTeamsChatText = gs.getMessage("Start teams chat");
return result;
},
getOpenedForInfo: function() {
var openedFor = {};
var openedForRef = this._gr.opened_for.getRefRecord();
openedFor.avatar = openedForRef.avatar ? "/" + openedForRef.avatar + ".iix?t=small" : "";
openedFor.name = this._gr.getDisplayValue("opened_for");
openedFor.sys_id = this._gr.getValue("opened_for");
openedFor.title = openedForRef.title ? [{
"label": openedForRef.getDisplayValue("title")
}] : [];
openedFor.vip = openedForRef.vip ? [{
"label": "VIP",
"color": "critical"
}] : [];
return openedFor;
},
getAppointmentInfo: function() {
var appointmentInfo = {
fields: [],
heading: ''
};
appointmentInfo.fields.push({
"label": gs.getMessage("Location"),
"value": {
"type": "string",
"value": this._gr.getDisplayValue("location")
}
});
if (this._contextGr) {
var walkupType = ((this._contextGr.getValue("is_appointment") === "1") ? gs.getMessage("Appointment - {0}", this._contextGr.getDisplayValue("contact_type")) : gs.getMessage("Check-in"));
appointmentInfo.heading = (this._contextGr.getValue("is_appointment") === "1") ? gs.getMessage('Appointment') : gs.getMessage("Checked-in");
appointmentInfo.fields.push({
"label": gs.getMessage("Walkup type"),
"value": {
"type": "string",
"value": walkupType
}
});
}
if (this._contextGr.getValue("is_appointment") === "1") {
if (this._appointmentGr) {
appointmentInfo.fields.push({
"label": gs.getMessage("Scheduled on"),
"value": {
"type": "string",
"value": this._appointmentGr.getDisplayValue("window_start")
}
});
}
} else {
appointmentInfo.fields.push({
"label": gs.getMessage("Checked-in at"),
"value": {
"type": "string",
"value": this._contextGr.getDisplayValue("sys_created_on")
}
});
}
return appointmentInfo;
},
getContextInfo: function() {
var contextInfo = {
isAppointment: false,
isRemote: false,
hasSourceIncident: false,
hideKioskMessage: false,
kioskEnabledForLocation: false,
kioskMessage: ''
};
if (this._contextGr) {
contextInfo.isAppointment = (this._contextGr.getValue("is_appointment") === "1");
contextInfo.isRemote = (this._contextGr.getValue("contact_type") === "remote");
contextInfo.canStartTeamsChat = this._canStartTeamsChat();
}
contextInfo.hasSourceIncident = (this._sourceIncidentGr != null);
return contextInfo;
},
getSourceIncidentInfo: function() {
var inicdentInfo = {
hideSection: true
};
inicdentInfo.heading = gs.getMessage("Source");
var gr = new GlideRecord(this.TABLES.INTERACTION_RELATED_RECORD);
gr.addQuery('interaction', this._grSysId);
gr.addQuery('task.sys_class_name', 'incident');
gr.query();
if (gr.next()) {
inicdentInfo.hideSection = false;
var parentIncidentGr = new GlideRecord(gr.getValue("document_table"));
var document_id = gr.getValue('document_id');
if (!gs.nil(document_id) && parentIncidentGr.get(gr.getValue('document_id'))) {
inicdentInfo.recordInfo = {
number: parentIncidentGr.getDisplayValue("number"),
sys_id: parentIncidentGr.getUniqueValue(),
table: 'incident',
priority: (this._getFieldsInfo(parentIncidentGr, ['priority'])[0]),
shortDescription: parentIncidentGr.getDisplayValue("short_description"),
contentData: this._getFieldsInfo(parentIncidentGr, ['assigned_to', 'state'])
};
}
}
return inicdentInfo;
},
_canStartTeamsChat: function() {
if(GlidePluginManager.isActive('com.snc.uib.sow_collaboration') && GlidePluginManager.isActive('com.snc.ms_teams') && GlidePluginManager.isActive('com.snc.tcm_collab_hook')) {
return (new sn_walkup.WalkUpUtil()).canStartMSTeamsChat(this._gr) && new sn_tcm_collab_hook.MSTeamsChatUtil().canLaunchChat(this._gr, 'sn_walkup.walkup_technician');
}
return false;
},
type: 'WalkupInteractionInfoSNC'
};
Sys ID
05258d82e1173010f87710c901e3230d