Name
sn_sow_chg.ChangeRiskSNC
Description
No description available
Script
var ChangeRiskSNC = Class.create();
ChangeRiskSNC.prototype = {
TABLES: {
SYS_USER_GRMEMBER: 'sys_user_grmember',
SYS_USER: 'sys_user'
},
initialize: function (gr) {
this._gr = gr;
this._grSysId = gr.getUniqueValue().toString();
},
// get data required for change contextual sidebar
getRecordInfo: function () {
var result = {};
result.headerInfo = this.getHeaderInfo();
result.change_request = this.getChangeRequestFields();
result.riskActions = this.getRiskActions();
result.changeDateInfo = this.getChangeDateInfo();
result.loggedInUserGroup = this.getLoggedInUserGroup();
result.cabMeeting = this.getCABMeeting();
return result;
},
// get header data for change contextual sidebar
getHeaderInfo: function () {
var result = {};
result.mainHeading = gs.getMessage('Record information');
var updatedBy;
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'))
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;
},
getChangeRequestFields: function () {
var result = {};
result.state = {
value: this._gr.getValue('state'),
display_value: this._gr.state.getDisplayValue()
};
result.model = {
label: gs.getMessage('{0} success score', this._gr.chg_model.getLabel()),
value: this._gr.getValue('chg_model'),
display_value: this._gr.chg_model.getDisplayValue()
};
result.type = {
label: gs.getMessage('{0} success score', this._gr.type.getLabel()),
value: this._gr.getValue('type'),
display_value: this._gr.type.getDisplayValue()
};
result.risk = {
label: this._gr.risk.getLabel(),
value: this._gr.getValue('risk'),
display_value: this._gr.risk.getDisplayValue()
};
result.impactStacked = [];
var impactStacked = {
label: this._gr.impact.getLabel(),
value: {
type: 'html',
value: '<span>' + this._gr.impact.getDisplayValue() + '</span>'
}
};
result.impactStacked.push(impactStacked);
result.riskEvaluatorStacked = this.getRiskEvaluator();
result.assignmentGroupStacked = [];
var assignmentGroupStacked = {
label: this._gr.assignment_group.getLabel(),
value: this._gr.assignment_group.getDisplayValue(),
clickable: false,
id: this._gr.getValue('assignment_group') + '-link'
};
result.assignmentGroupStacked.push(assignmentGroupStacked);
result.assignment_group = {
label: this._gr.assignment_group.getLabel(),
value: this._gr.getValue('assignment_group'),
display_value: this._gr.assignment_group.getDisplayValue()
};
result.assigned_to = {
sysId: this._gr.assigned_to + '',
label: this._gr.assigned_to.getLabel(),
labelAction: this._gr.assignment_group ? gs.getMessage('Assign') : gs.getMessage('Assign to me'),
labelUnassigned: gs.getMessage('This change has not been assigned yet'),
value: {
type: 'string',
value: this._gr.assigned_to.getDisplayValue()
},
caller: this.getUserProfile(this._gr.assigned_to.getRefRecord()),
actions: {
label: gs.getMessage('Secondary assigned to actions'),
contactAction: {
label: gs.getMessage('Contact')
},
reassignAction: {
label: gs.getMessage('Reassign')
}
}
};
result.requested_by = {
sysId: this._gr.requested_by + '',
label: this._gr.requested_by.getLabel(),
value: {
type: 'string',
value: this._gr.requested_by.getDisplayValue()
},
caller: this.getUserProfile(this._gr.requested_by.getRefRecord())
};
if (this.isPluginActive('com.snc.change_management.change_success_score')) {
result.change_success_score = new sn_chg_score.ChangeSuccess().getScoresForChange(this._gr);
if (result.change_success_score.team_success_score)
result.change_success_score.team_success_score.label = gs.getMessage('Change success score');
}
result.riskCard = {
label: gs.getMessage('Scorecard')
};
return result;
},
getRiskActions: function () {
return new SOWChangeUtils().calculateRisk(this._gr.getUniqueValue());
},
isPluginActive: function(plugin) {
return ((GlidePluginManager.isActive(plugin) + '').toLowerCase() === 'true');
},
getRiskEvaluator: function() {
var result = [];
if (!this.isPluginActive('com.snc.change_management.success_probability'))
return result;
var changeProbabilityDetailsGr = new GlideRecord('sn_chg_probability_details');
changeProbabilityDetailsGr.addQuery('change_request', this._gr.getUniqueValue());
changeProbabilityDetailsGr.query();
if (!changeProbabilityDetailsGr.next())
return result;
var probabilitySuccess = {
label: gs.getMessage('Probability of success'),
value: {
type: 'html',
value: '<span>' + changeProbabilityDetailsGr.new_probability.getDisplayValue() + '</span>'
}
};
result.push(probabilitySuccess);
return result;
},
getChangeDateInfo: function () {
var result = {};
result.heading = gs.getMessage('Schedule');
result.planned = [];
result.actual = [];
var plannedStart = {
label: this._gr.start_date.getLabel(),
value: {
type: 'string',
value: this._gr.start_date ? this._gr.start_date.getDisplayValue() : '-'
}
};
var plannedEnd = {
label: this._gr.end_date.getLabel(),
value: {
type: 'string',
value: this._gr.end_date ? this._gr.end_date.getDisplayValue() : '-'
}
};
result.plannedHasValue = !!(this._gr.start_date || this._gr.end_date);
var actualStart = {
label: this._gr.work_start.getLabel(),
value: {
type: 'string',
value: this._gr.work_start ? this._gr.work_start.getDisplayValue() : '-'
}
};
var actualEnd = {
label: this._gr.work_end.getLabel(),
value: {
type: 'string',
value: this._gr.work_end ? this._gr.work_end.getDisplayValue() : '-'
}
};
result.actualHasValue = !!(this._gr.work_start || this._gr.work_end);
result.planned.push(plannedStart);
result.planned.push(plannedEnd);
result.actual.push(actualStart);
result.actual.push(actualEnd);
return result;
},
getUserProfile: function (userGr) {
if (!userGr)
return {};
var userSysId = userGr.getUniqueValue();
var userInfo = {
userID: userSysId,
avatar: userGr.avatar ? '/' + userGr.avatar + '.iix?t=small' : '',
initials: this._getInitials(userGr.getValue('name')),
name: userGr.name.getDisplayValue(),
title: userGr.title ? userGr.title.getDisplayValue() : '-',
vip: userGr.vip ? [{ label: gs.getMessage('VIP'), color: 'critical' }] : [],
department: userGr.department.getDisplayValue(),
timeZone: userGr.time_zone.getDisplayValue() || ''
};
var businessPhoneVal = userGr.phone.getDisplayValue() + '';
if(businessPhoneVal){
userInfo.phone = {
id: 'phone',
label: userGr.phone.getLabel(),
value: businessPhoneVal,
type: 'phone',
clickable: true
};
}
var mobilePhoneVal = userGr.mobile_phone.getDisplayValue() + '';
if(mobilePhoneVal){
userInfo.mobile = {
id: 'mobile',
label: userGr.mobile_phone.getLabel(),
value: mobilePhoneVal,
type: 'phone',
clickable: true
};
}
if(userGr.email.canRead()){
var emailVal = userGr.email + '';
if(emailVal){
userInfo.email = {
id: 'email',
label: userGr.email.getLabel(),
value: emailVal,
type: 'email',
clickable: true
};
}
}
if(userGr.location){
var location = userGr.location.getRefRecord();
var state = location.getDisplayValue('state') + '';
var city = location.getDisplayValue('city') + '';
if(city || state){
var locationVal = state && city ? city + ', ' + state : state ? state : city;
userInfo.location = {
id: 'location',
label: location.getLabel(),
value: locationVal,
type: 'address'
};
}
}
return userInfo;
},
getLoggedInUserGroup: function() {
var result = [];
var groupGr = new GlideRecord('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;
},
getCABMeeting: function() {
var result = {};
result.label = gs.getMessage('CAB meeting');
var cabAgendaItemSysIds = [];
var cabAgendaItemGr = new GlideRecord('cab_agenda_item');
cabAgendaItemGr.addQuery('state', 'IN', 'in_progress,pending');
cabAgendaItemGr.addQuery('task', this._gr.getUniqueValue());
cabAgendaItemGr.query();
while (cabAgendaItemGr.next())
cabAgendaItemSysIds.push(cabAgendaItemGr.cab_meeting + '');
result.hasMeeting = cabAgendaItemSysIds.length > 0;
if (!result.hasMeeting)
return result;
var cabMeetingGr = new GlideRecord('cab_meeting');
cabMeetingGr.addQuery('sys_id', cabAgendaItemSysIds);
cabMeetingGr.addQuery('state', 'IN', 'in_progress,pending');
cabMeetingGr.orderBy('start');
cabMeetingGr.query();
if (cabMeetingGr.next()) {
result.cabStacked = [];
result.cabStacked.push({
label: cabMeetingGr.name.getLabel(),
value: {
type: 'string',
value: cabMeetingGr.name.getDisplayValue()
}
});
result.cabStacked.push({
label: cabMeetingGr.start.getLabel(),
value: {
type: 'string',
value: cabMeetingGr.start.getDisplayValue()
}
});
result.cabStacked.push({
label: cabMeetingGr.manager.getLabel(),
value: {
type: 'string',
value: cabMeetingGr.manager.getDisplayValue()
}
});
result.cabLink = '/cab/?id=cab_workbench&sys_id=' + cabMeetingGr.getUniqueValue();
} else
result.hasMeeting = false;
return result;
},
_getInitials: function (fullname) {
if (!fullname)
return '';
var names = fullname.split(' ');
var initials = '';
names.forEach(function (name) {
initials += name[0];
});
return initials;
},
type: 'ChangeRiskSNC'
};
Sys ID
e888367853921110532cddeeff7b1235