Name
sn_sow_inc.SOWIncidentInfoSNC
Description
No description available
Script
var SOWIncidentInfoSNC = Class.create();
SOWIncidentInfoSNC.prototype = {
TABLES: {
SYS_USER_GRMEMBER: 'sys_user_grmember',
TASK_SLA: 'task_sla',
SYS_USER: 'sys_user',
INCIDENT_TASK: 'incident_task',
SYS_AUDIT: 'sys_audit'
},
FIELDS: {
SOURCE: ['contact_type', 'opened_by']
},
//Supported Colors for highlighted value - ("critical" | "high" | "warning" | "moderate" | "positive" | "info" | "low" | "magenta" | "pink" | "orange" | "yellow" | "brown" | "green" | "green-yellow" | "blue" | "gray" | "teal" | "purple")
FIELD_DETAILS: {
'priority': {
'type': 'highlighted-value',
'color_map': {
'1': 'orange',
'2': 'brown',
'3': 'green-yellow',
'4': 'blue',
'5': 'green'
}
},
'default': {
'type': 'string'
}
},
initialize: function(gr) {
this._gr = gr;
this._grSysId = gr.getUniqueValue().toString();
this.sowITSMHighlightedColorUtil = new sn_sow_itsm_common.SOWITSMHighlightedColorUtils();
},
getRecordInfo: function() {
var result = {};
result.headerInfo = this.getHeaderInfo();
result.sourceHeading = gs.getMessage('Origin');
result.sourceInfo = this.getSourceInfo();
result.assignedUserInfo = this.getAssignedUserInfo();
result.slaConfig = this.getSLAConfig();
result.slaInfo = this.getSlaInfo();
result.contributorsInfo = this.getContributorsInfo();
result.incidentInfo = this.getIncidentAssignmentInfo();
result.loggedInUserGroup = this.getLoggedInUserGroup();
return result;
},
getHeaderInfo: function() {
var result = {};
result.mainHeading = gs.getMessage('Record Information');
var userGr = new GlideRecord(this.TABLES.SYS_USER);
userGr.addActiveQuery();
userGr.addQuery("user_name", this._gr.getDisplayValue('sys_updated_by'));
userGr.query();
if (userGr.next() && userGr.getValue('name'))
var updatedBy = userGr.getValue('name');
else
updatedBy = this._gr.getDisplayValue('sys_updated_by');
result.updateMsg = gs.getMessage("Last updated by {0}", updatedBy);
result.updatedTime = this._gr.sys_updated_on.getDisplayValue();
return result;
},
getFieldsInfo: function(fields) {
var result = [];
for (var i = 0; i < fields.length; i++) {
var field = fields[i];
var value = this._gr.getDisplayValue(field);
if (value) {
var item = {};
item.label = this._gr[field].getLabel();
item.value = {};
item.value.type = this.FIELD_DETAILS[field] ? this.FIELD_DETAILS[field]['type'] : this.FIELD_DETAILS['default']['type'];
if (item.value.type == 'highlighted-value') {
item.value.label = value;
item.value.status = this.FIELD_DETAILS[field]['color_map'][this._gr.getValue(field)];
} else {
item.value.value = value;
}
result.push(item);
}
}
return result;
},
getSourceInfo: function() {
var result = {};
result.showCallerInfo = false;
result.showOriginInfo = false;
if (!gs.nil(this._gr.caller_id)) {
result.showCallerInfo = true;
result.callerInfo = this.getCallerInfo();
}
if (!gs.nil(this._gr.origin_table)) {
result.showOriginInfo = true;
result.originInfo = this.getOriginInfo();
}
return result;
},
getCallerInfo: function() {
var result = {};
var caller = {};
var callerRef = this._gr.caller_id.getRefRecord();
caller.sysId = callerRef.getUniqueValue();
caller.avatar = callerRef.avatar ? "/" + callerRef.avatar + ".iix?t=small" : "";
caller.name = this._gr.getDisplayValue("caller_id");
caller.timeZone = gs.getProperty('glide.sys.default.tz') || 'America/Los_Angeles';
if (callerRef.title)
caller.title = callerRef.getDisplayValue("title");
if (callerRef.department)
caller.department = callerRef.getDisplayValue("department");
var locationRef = callerRef.location.getRefRecord();
if (locationRef && locationRef.city)
caller.city = locationRef.getDisplayValue("city");
if (callerRef.time_zone)
caller.timeZone = callerRef.getDisplayValue("time_zone");
if (callerRef.vip)
caller.vip = [{
"label": gs.getMessage("VIP"),
"color": "critical"
}];
result.caller = caller;
result.secondaryInfo = this.getFieldsInfo(this.FIELDS.SOURCE);
return result;
},
getOriginInfo: function() {
var result = {
tagline: null,
actions: null,
heading: null,
content: null,
footerContent: null,
table: this._gr.origin_table + '',
sysId: this._gr.origin_id + ''
};
var originGr = new GlideRecord(this._gr.origin_table);
if (originGr.get(this._gr.origin_id)) {
if (this._gr.origin_table == "change_request") {
result.tagline = {
"label": originGr.getDisplayValue("number")
};
result.heading = {
"label": originGr.getDisplayValue("short_description")
};
result.content = [];
if (!gs.nil(originGr.risk)) {
var color = this.sowITSMHighlightedColorUtil.getHighlightedColor(originGr, 'risk');
var displayValue = originGr.getDisplayValue("risk");
var label = originGr.risk.getLabel();
var pair = {
"label": label,
"value": displayValue
};
if (!gs.nil(color)) {
color.label = displayValue;
color.type = "highlighted-value";
color.status = color.color;
pair.value = color;
}
result.content.push(pair);
}
if (!gs.nil(originGr.state)) {
color = this.sowITSMHighlightedColorUtil.getHighlightedColor(originGr, 'state');
displayValue = originGr.getDisplayValue("state");
label = originGr.state.getLabel();
pair = {
"label": label,
"value": displayValue
};
if (!gs.nil(color)) {
color.label = displayValue;
color.type = "highlighted-value";
color.status = color.color;
pair.value = color;
}
result.content.push(pair);
}
if (!gs.nil(originGr.cmdb_ci)) {
result.content.push({
"label": originGr.cmdb_ci.getLabel(),
"value": {
"type": "text-link",
"label": originGr.getDisplayValue("cmdb_ci"),
"href": "javascript:void(0)",
"data": {
"table": "cmdb_ci",
"sysId": originGr.getValue("cmdb_ci")
}
}
});
}
if (!gs.nil(originGr.assignment_group))
result.content.push({
"label": originGr.assignment_group.getLabel(),
"value": originGr.getDisplayValue("assignment_group")
});
if (!gs.nil(originGr.assigned_to))
result.content.push({
"label": originGr.assigned_to.getLabel(),
"value": originGr.getDisplayValue("assigned_to")
});
result.footerContent = {
"label": originGr.sys_updated_on.getLabel(),
"value": originGr.sys_updated_on.getDisplayValue(),
"reversed": false
};
} else if (this._gr.origin_table == "em_alert") {
result.tagline = {
"label": originGr.getDisplayValue("number")
};
result.heading = {
"label": originGr.getDisplayValue("description")
};
result.content = [];
if (!gs.nil(originGr.sn_priority_group)) {
color = this.sowITSMHighlightedColorUtil.getHighlightedColor(originGr, 'sn_priority_group');
displayValue = originGr.getDisplayValue("sn_priority_group");
label = originGr.sn_priority_group.getLabel();
pair = {
"label": label,
"value": displayValue
};
if (!gs.nil(color)) {
color.label = displayValue;
color.type = "highlighted-value";
color.status = color.color;
pair.value = color;
}
result.content.push(pair);
}
if (!gs.nil(originGr.severity)) {
color = this.sowITSMHighlightedColorUtil.getHighlightedColor(originGr, 'severity');
displayValue = originGr.getDisplayValue("severity");
label = originGr.severity.getLabel();
pair = {
"label": label,
"value": displayValue
};
if (!gs.nil(color)) {
color.label = displayValue;
color.type = "highlighted-value";
color.status = color.color;
pair.value = color;
}
result.content.push(pair);
}
if (!gs.nil(originGr.cmdb_ci)) {
result.content.push({
"label": originGr.cmdb_ci.getLabel(),
"value": {
"type": "text-link",
"label": originGr.getDisplayValue("cmdb_ci"),
"href": "javascript:void(0)",
"data": {
"table": "cmdb_ci",
"sysId": originGr.getValue("cmdb_ci")
}
}
});
}
result.footerContent = {
"label": originGr.sys_updated_on.getLabel(),
"value": originGr.sys_updated_on.getDisplayValue(),
"reversed": false
};
}
}
return result;
},
isMemberOfGroup: function(userId, groupId) {
if (!groupId || !userId)
return false;
var groupGr = new GlideRecord(this.TABLES.SYS_USER_GRMEMBER);
groupGr.addQuery('group.active', 'true');
groupGr.addQuery('group', groupId);
groupGr.addQuery('user', userId);
groupGr.query();
return groupGr.hasNext();
},
getMemberGroup: function(userId) {
if (!userId)
return '';
var groupGr = new GlideRecord(this.TABLES.SYS_USER_GRMEMBER);
groupGr.addQuery('group.active', 'true');
groupGr.addQuery('user', userId);
groupGr.setLimit(1);
groupGr.query();
if (groupGr.next()) {
return groupGr.group.getDisplayValue();
}
return '';
},
getAssignedUserInfo: function() {
var result = {};
result.isAssignedToFilled = true;
result.hideEmptyState = true;
result.emptyStateMsg = gs.getMessage("This Incident has not been assigned yet");
result.showAssignButton = Boolean(this._gr.active);
result.subHeading = this._gr.assigned_to.getLabel();
if (!this._gr.assigned_to) {
result.isAssignedToFilled = false;
result.hideEmptyState = false;
return result;
}
var assignedUserRef = this._gr.assigned_to.getRefRecord();
result.avatar = assignedUserRef.avatar ? "/" + assignedUserRef.avatar + ".iix?t=small" : "";
result.name = this._gr.getDisplayValue("assigned_to");
if (this._gr.assignment_group && this.isMemberOfGroup(this._gr.assigned_to, this._gr.assignment_group)) {
result.group = [{
"label": this._gr.getDisplayValue("assignment_group")
}];
} else {
var group = this.getMemberGroup(this._gr.assigned_to);
result.group = group ? [{
"label": group
}] : [];
}
return result;
},
getSLAConfig: function() {
var config = [{
"configId": "af871ab3532730102d05ddeeff7b124f",
"slaTimerLabel": gs.getMessage("Response SLA"),
"timeLabel": gs.getMessage("Time to respond")
},
{
"configId": "aca7d6b3532730102d05ddeeff7b12ec",
"slaTimerLabel": gs.getMessage("Resolution SLA"),
"timeLabel": gs.getMessage("Time to resolve")
}
];
return config;
},
getSlaInfo: function() {
var result = {};
var aggGr = new GlideAggregate(this.TABLES.TASK_SLA);
aggGr.addQuery('task', this._grSysId);
aggGr.addAggregate("COUNT");
aggGr.query();
result.count = 0;
if (aggGr.next()) {
result.count = aggGr.getAggregate('COUNT');
result.buttonText = gs.getMessage("View {0} more SLAs", result.count);
result.query = aggGr.getEncodedQuery();
}
result.listTitle = gs.getMessage("Task SLA");
return result;
},
getContributorsInfo: function() {
var contributorsList = [];
var arrayUtil = new global.ArrayUtil();
var incidentTaskGr = new GlideRecord(this.TABLES.INCIDENT_TASK);
incidentTaskGr.addQuery('incident', this._grSysId);
incidentTaskGr.addNotNullQuery('assigned_to');
incidentTaskGr.query();
while (incidentTaskGr.next()) {
if (incidentTaskGr.getValue('assigned_to') != this._gr.assigned_to && !arrayUtil.contains(contributorsList, incidentTaskGr.getValue('assigned_to'))) {
contributorsList.push(incidentTaskGr.getValue('assigned_to'));
}
}
var collaboratorsList = new sn_sow.SOWCollabInfo().getCollaboratorsInfo('incident', this._grSysId);
for (var j = 0; j < collaboratorsList.length; j++) {
if (!arrayUtil.contains(contributorsList, collaboratorsList[j]))
contributorsList.push(collaboratorsList[j]);
}
var sysAuditGr = new GlideRecord(this.TABLES.SYS_AUDIT);
sysAuditGr.addQuery('tablename', 'incident');
sysAuditGr.addQuery('documentkey', this._grSysId);
sysAuditGr.addQuery('fieldname', 'assigned_to');
sysAuditGr.addNotNullQuery('oldvalue');
sysAuditGr.query();
while (sysAuditGr.next()) {
if (sysAuditGr.getValue('oldvalue') != this._gr.assigned_to && !arrayUtil.contains(contributorsList, sysAuditGr.getValue('oldvalue'))) {
contributorsList.push(sysAuditGr.getValue('oldvalue'));
}
}
var userInfo = this.getUserInfo(contributorsList);
var contributors = [];
for (var i = 0; i < contributorsList.length; i++) {
if (userInfo[contributorsList[i]]) {
contributors.push({
sys_id: contributorsList[i],
avatar: userInfo[contributorsList[i]].avatar,
userDisplayValue: userInfo[contributorsList[i]].userDisplayValue
});
}
}
return contributors;
},
getUserInfo: function(userIds) {
var results = [];
var userGr = new GlideRecord(this.TABLES.SYS_USER);
userGr.addQuery('sys_id', 'IN', userIds.join(","));
userGr.query();
while (userGr.next()) {
results[userGr.getUniqueValue()] = {
avatar: userGr.getValue('avatar') ? "/" + userGr.getValue('avatar') + ".iix?t=small" : "",
userDisplayValue: userGr.getDisplayValue()
};
}
return results;
},
getIncidentAssignmentInfo: function() {
var result = {};
result.assignmentGroup = this._gr.getValue("assignment_group");
result.assignedTo = this._gr.getValue("assigned_to");
return result;
},
getLoggedInUserGroup: function() {
var result = [];
var groupGr = new GlideRecord(this.TABLES.SYS_USER_GRMEMBER);
groupGr.addQuery('group.active', 'true');
groupGr.addQuery('user', gs.getUserID());
groupGr.query();
while (groupGr.next()) {
result.push({
displayValue: groupGr.group.getDisplayValue(),
value: groupGr.getValue('group')
});
}
return result;
},
type: 'SOWIncidentInfoSNC'
};
Sys ID
9dd95cb7530230108e4dddeeff7b1223