Email notification script help (Reqeust Complete)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
I'm trying to edit an email script (that is referenced by "Request Complete" email notification) to display the RITM short description.
The script it is referencing task.item and I think it should be referencing task.short_description (sc_request table extends to the task table). It doesn't find a value when referencing task.short_description. Just returns "undefined." I also tried sq_reqeust.task.short_description (which I didn't think would work but I'm stuck).
I was unable to copy the script so I created a new one and pasted the code from original script. This new script has as new name and is being referenced in my notification. How can I get the script to reference and display the RITM short description?
Origanl code:
Modified code:
FYI the script I'm working with is About_The_Request_Req_Survey_Req_Completed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago - last edited 2 hours ago
Hello @ElizabethG22728
Here is the Updated Email script "About_The_Request_Req_Survey_Req_Completed" - Please find the updated code in between comments //Modified here: Starts and //Modified here: Ends
(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */
email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */
event) {
var portalSuffix = new sn_ex_emp_fd.FoundationNotificationUtil().getPortalSuffix();
var viewAllUrl = '/' + portalSuffix + '?id=order_status&table=sc_request&sys_id=' + current.sys_id;
var requestUrl = '';
var buttonText = '';
if (email_action.sys_name.toString() === 'Request survey') {
requestUrl = event.parm2;
buttonText = gs.getMessage('Take the survey');
} else {
requestUrl = viewAllUrl;
buttonText = gs.getMessage('View request');
}
//Generates primary action of view request
var requestNotificationJs = new global.RequestNotificationUtil();
requestNotificationJs.createNotificationPrimayAction(template, requestUrl, buttonText);
if (email_action.sys_name.toString() === 'Request survey') {
template.print('<div style="font-size: 15pt; line-height: 30px; padding-bottom: 16px;"><span style="font-weight:600">About your recent request</span></div>');
} else {
template.print('<div style="font-size: 15pt; line-height: 30px; padding-bottom: 16px;"><span style="font-weight:600">About this request</span></div>');
}
//request details required for notification template
var requestDetails = requestNotificationJs.getRequestDetails(current.sys_id, current);
var requestItemPadding = '';
if (email_action.sys_name.toString() === 'Request completed' && !current.close_notes.nil()) {
var comments = current.close_notes.toString();
comments = comments.replace(/\n/g, '<br/>');
template.print('<div> Completed by : ' + '<b style="font-weight:600">' + current.closed_by.name + '</b></div>');
template.print('<div> Completion notes : ' + '<b style="font-weight:600">' + comments + '</b></div>');
requestItemPadding = 'padding-top:16px;';
}
if (email_action.sys_name.toString() === 'Request approved') {
var comment = requestNotificationJs.getRequestComment(current.sys_id, 'approved');
if (comment) {
template.print('<div> Approval notes : ' + '<b style="font-weight:600">' + comment + '</b></div>');
requestItemPadding = 'padding-top:16px;';
}
}
if (requestDetails.totalTasks > 1) {
template.print('<div style="font-size: 12pt;font-weight:600;' + requestItemPadding + '">Requested items (' + requestDetails.totalTasks + ')</div>');
requestItemPadding = 'padding-top:16px;';
}
requestDetails.tasks.forEach(function(task, index) {
var borderBottom = 'border-bottom:1px solid #DADDE2';
template.print('<div style="padding-bottom:16px;' + requestItemPadding);
if (requestDetails.totalTasks > requestDetails.tasks.length || (index + 1 < requestDetails.tasks.length)) {
template.print(borderBottom);
}
//Modified here: Starts
var ritmShortDesc = '';
if (task.requestNumber) {
var ritmGR = new GlideRecord('sc_req_item');
ritmGR.addQuery('number', task.requestNumber);
ritmGR.setLimit(1);
ritmGR.query();
if (ritmGR.next()) {
ritmShortDesc = ritmGR.short_description.getDisplayValue();
}
}
template.print('">');
template.print('Requested item number: <b style="font-weight:600">' + task.requestNumber + '</b><br/>' + 'RITM Short description: <b style="font-weight:600">' + ritmShortDesc + '</b><br/>' + 'Request Short description: <b style="font-weight:600">' + current.short_description.getDisplayValue() + '</b><br/>');
template.print('</div>');
});
//Modified here: Ends
if (requestDetails.totalTasks > 3) {
template.print('<div style="padding-bottom:18px;padding-top:16px;color:#3C59E7"><a href="' + viewAllUrl + '">');
template.print(gs.getMessage('View all items'));
template.print('</a></div>');
}
})(current, template, email, email_action, event);
template.print('">');
template.print('Requested item number: <b style="font-weight:600">' + task.requestNumber + '</b><br/>' + 'RITM Short description: <b style="font-weight:600">' + task.item + '</b><br/>' + 'Request Short description: <b style="font-weight:600">' + current.short_description.getDisplayValue() + '</b><br/>');
template.print('</div>');
Validation Results:
Hope that helps!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
I believe 'task' is an OOTB object, so you cannot reference short_description like 'task.short_description'. 'current' object is available so try using current.short_description.
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
45m ago
1. If notification is on sc_req_item table then use current.short_description
Sample_code:
(function runMailScript(current, template, email, email_action, event)
{
if (current.short_description)
{
template.print(current.short_description);
} else
{
template.print("No RITM short description available.");
}
})(current, template, email, email_action, event);
2. If notification is on sc_request table , use
a. in email script -
var gr = new GlideRecord("sc_req_item");
3. If notification on task table ,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
21m ago
Instead of scripting, can you use the native editor w/ drag-and-drop pills?
