Skip to content

Commit 0b359b3

Browse files
authored
RITM rejection notes (ServiceNowDevProgram#720)
* Create reject_reason_new After finding that reject reasons added from Employee Center for Requests do not get added to the Approval record but instead the RITM record, I made a change to the reject_reason email script to include the RITM reject reason (if found) * Create README.md * Create RequestNotificationUtil After finding that reject reasons added from Employee Center for Requests do not get added to the Approval record but instead the RITM record, I made a change to the reject_reason email script to include the RITM reject reason (if found). The email script calls this Script Include to pull the reject reason journal entry from the RITM record * Rename reject_reason_new to reject_reason_new.js * Rename RequestNotificationUtil to RequestNotificationUtil.js * Updated path to include subfolder for RequestNotificationUtil * Create readme.MD for RequestNotificationUtil
1 parent f05860a commit 0b359b3

File tree

4 files changed

+91
-0
lines changed

4 files changed

+91
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
After finding that reject reasons added from Employee Center for Requests do not get added to the Approval record but instead the RITM record, I made a change to the reject_reason email script to include the RITM reject reason (if found)
2+
The changes calls the Script Include "RequestNotificationUtil" with an added function to call the RITM reject reason
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
2+
/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
3+
/* Optional GlideRecord */ event) {
4+
5+
var requestId = current;
6+
var portalSuffix = new sn_ex_emp_fd.FoundationNotificationUtil().getPortalSuffix();
7+
var requestUrl = '/' + portalSuffix + '?id=order_status&table=sc_request&sys_id=' + current.sys_id.toString();
8+
var fontSize = 'font-size: 16px;';
9+
var lineHeight = 'line-height: 24px;';
10+
var notificationUtil = new RequestNotificationUtil();
11+
12+
var requestDetails = notificationUtil.getRequestDetails(current.sys_id, current);
13+
var tasks = requestDetails.tasks;
14+
var totalTasks = requestDetails.totalTasks;
15+
16+
notificationUtil.createNotificationPrimayAction(template, requestUrl, 'View request');
17+
template.print('<div style="font-size: 15pt; line-height:30px;"><b>About this request</b></div>');
18+
19+
var commentLeft = notificationUtil.getRequestComment(current.sys_id, current.approval);
20+
if (commentLeft) {
21+
template.print('<div style="padding-top: 16px; ' + fontSize + lineHeight + '"><span>Rejection notes: </span>' + '<span style="font-weight: 600;">' + commentLeft + '</span></div>');
22+
}
23+
//For reject comments added to RITM record
24+
var commentLeftRITM = notificationUtil.getRejectCommentRITM(current.sys_id);
25+
if (commentLeftRITM) {
26+
template.print('<div style="padding-top:18px; ' + fontSize + lineHeight + '"><span>Rejection notes: </span>' + '<span style="font-weight: 600;">' + commentLeftRITM + '</span></div><br />');
27+
}
28+
if (requestDetails.totalTasks > 1) {
29+
template.print('<div style="font-size: 15pt;padding-top:16px;font-weight:600;">Requested items (' + requestDetails.totalTasks + ')</div>');
30+
}
31+
tasks.forEach(function (task, index) {
32+
var borderBottom = 'border-bottom:1px solid #DADDE2';
33+
template.print('<div style="padding-top:16px;padding-bottom:16px;');
34+
if (requestDetails.totalTasks > requestDetails.tasks.length || (index + 1 < requestDetails.tasks.length)) {
35+
template.print(borderBottom);
36+
}
37+
template.print('">');
38+
template.print('<div style="' + fontSize + lineHeight + '"><span>Requested item number:</span> <span style="font-weight: 600;">' + task.requestNumber + '</span></div>');
39+
template.print('<div style="' + fontSize + lineHeight + '"><span>Short description: </span><span style="font-weight: 600;">' + task.item + '</span></div>');
40+
template.print('</div>');
41+
});
42+
43+
if (totalTasks > 3) {
44+
template.print('<div style="' + fontSize + lineHeight + 'padding-top:16px; padding-bottom:16px;"><a style="color:#3C59E7" href="' + requestUrl + '">');
45+
template.print(gs.getMessage('View all items'));
46+
template.print('</a></div>');
47+
}
48+
})(current, template, email, email_action, event);
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
var RequestNotificationUtil = Class.create();
2+
RequestNotificationUtil.prototype = Object.extendsObject(RequestNotificationUtilSNC, {
3+
initialize: function() {
4+
RequestNotificationUtilSNC.prototype.initialize.apply(this, arguments);
5+
},
6+
7+
/**
8+
* Get Reject comment from RITM - found that rejection notes added in EC will post
9+
* to RITM record rather than Approval record
10+
* @param requestId - requestId
11+
* @returns comment based on the state for last rejected
12+
*/
13+
getRejectCommentRITM: function(requestId) {
14+
var ritmRecord = new GlideRecord("sc_req_item");
15+
ritmRecord.addQuery('request', requestId);
16+
ritmRecord.orderBy('sys_updated_on');
17+
ritmRecord.setLimit(1);
18+
ritmRecord.query();
19+
while (ritmRecord.next()) {
20+
var commentDesc = ritmRecord.comments.getJournalEntry(1).toString();
21+
if (commentDesc.length > 0 && commentDesc.indexOf("Reason for rejection:") > -1) {
22+
var split = commentDesc.split(/\(Additional comments\)/gi);
23+
if (split.length > 1) {
24+
// returns the first comment.
25+
var comment = split[split.length - 1];
26+
comment = comment.trim();
27+
var colonIndex = comment.indexOf(':');
28+
if (colonIndex != -1) {
29+
comment = comment.substr(colonIndex + 2, comment.length - 1);
30+
}
31+
comment = comment.replace(/\n/g, '<br/>');
32+
return comment;
33+
}
34+
}
35+
}
36+
},
37+
38+
type: 'RequestNotificationUtil'
39+
});
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
If a Request is rejected through Employee Center, the rejection notes get added to the RITM record rather than the Approval record. Therefore, the OOB reject notification does not contain the rejection comments.
2+
RequestNotificationUtil is used in reject_reason_new notification email script to pull RITM reject reason (if available)

0 commit comments

Comments
 (0)