Name
sn_hr_sp.emailUtil
Description
Contains functions used by HR email scripts and templates to determine whether to provide a link to the HR Service Portal or the regular form.
Script
var emailUtil = Class.create();
emailUtil.prototype = {
initialize: function(task, email) {
this._gr = task;
this._email = email;
this._util = new sn_hr_core.hr_Utils();
},
getLink : function() {
if (this._shouldGoToServicePortal())
return this._getPortalLink();
else
return this._getDefaultLink();
},
_shouldGoToServicePortal : function() {
if (this._isNotificationWhitelisted()) {
var taskType = this._getRecordType();
if (taskType == 'HR_CASE')
return this._checkCaseOpenedFor();
else if (taskType == 'HR_TASK')
return this._checkTaskAssignedTo();
}
return false;
},
_checkCaseOpenedFor : function() {
var sentToOpenedFor = this._email.recipient_fields.indexOf('opened_for') >= 0;
return sentToOpenedFor && this._shouldUserViewPortal(this._gr.opened_for);
},
_checkTaskAssignedTo : function() {
var sentToAssignedTo = this._email.recipient_fields.indexOf('assigned_to') >= 0;
return sentToAssignedTo && this._shouldUserViewPortal(this._gr.assigned_to);
},
_shouldUserViewPortal : function(userId) {
return this._util.userHasSPClientRole(userId) && !this._util.userHasHRRole(userId);
},
_isNotificationWhitelisted : function() {
var gr = new GlideRecord('sys_properties');
gr.get('name', 'sn_hr_sp.email_link');
var eligibleNotifications = gr.getValue('value');
if (!gs.nil(eligibleNotifications))
return eligibleNotifications.indexOf(this._email.sys_id) >= 0;
else
return false;
},
_getRecordType : function() {
var tables = new global.GlideTableHierarchy(this._gr.sys_class_name).getTables();
for (var i = 0; i < tables.length; i++) {
if (tables[i] == sn_hr_core.hr.TABLE_CASE)
return 'HR_CASE';
else if (tables[i] == sn_hr_core.hr.TABLE_TASK)
return 'HR_TASK';
}
return null;
},
_getPortalLink : function() {
var portalSuffix = new sn_hr_sp.hr_TicketPageConfigUtil().getActivePortalURLSuffix();
var type = this._getRecordType();
if(type == 'HR_CASE')
return gs.getProperty("glide.servlet.uri") + portalSuffix +'?sys_id=' + this._gr.sys_id + '&view=sp&id=' + new sn_hr_sp.hr_PortalUtil().ticketPage() + '&table=' + sn_hr_core.hr.TABLE_CASE + '&sysparm_url=true';
else
return gs.getProperty("glide.servlet.uri") + portalSuffix + '?id=' + new sn_hr_sp.todoPageUtils().getTodoPageId() + '&view=sp&sysparm_tableName='+ this._gr.sys_class_name +'&sys_id=' + this._gr.sys_id + '';
},
_getDefaultLink : function() {
return gs.getProperty("glide.servlet.uri") + 'nav_to.do?uri=' + this._gr.sys_class_name + '.do?sys_id=' + this._gr.sys_id + '&sysparm_stack=' + this._gr.sys_class_name + '_list.do&sysparm_query=active=true';
},
getRelevantLinkForUser : function(userId) {
if (this._util.userHasSPClientRole(userId))
return this._getPortalLink();
else
return this._getDefaultLink();
},
type: 'emailUtil'
};
Sys ID
3a462e4a539222003585c3c606dc341f