Email body content goes after the ending of email template
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-08-2023 02:42 AM
Hi Community members!
I have an issue with one email notification that's using email template with logo at the top and "Best regards, ..." at the bottom. Also there's email script in the email body that's displaying the table with info from RITM. This is my email notification:
This is HTML for this email notification:
When I preview it, everything looks great and there are no issues.
But when I tested it, it turned our like this:
The table somehow was at the bottom of the email, and the rest of email body ("No further action is required from you.") and the bottom of email template ("Best regards, ...") is going before it.
I don't understand why it's happening.
Any help will be much appreciated!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-08-2023 05:16 AM
I have tried to replicate this in a personal dev and cannot. Can you share the code inside the mail script? My guess is some action there is causing the content to be put at the bottom of the email instead of just where you put the mail script in the notification definition.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-08-2023 05:19 AM
Hi @Kristen Ankeny , here's the email script for the table:
(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */
email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */
event) {
var costO = current.sysapproval.price.getCurrencyDisplayValue();
var costR = current.sysapproval.recurring_price.getCurrencyDisplayValue();
var costF = current.sysapproval.recurring_frequency;
if (current.sysapproval.cat_item.u_model_designation_family != '') {
try {
var origUser = gs.getSession().impersonate(current.sysapproval.requested_for);
costO = current.sysapproval.price.getDisplayValue();
} finally {
gs.getSession().impersonate(origUser);
}
var coststringR = " ";
} else {
coststringR = costR + " " + costF;
}
var coststringO = costO + " One Time Cost";
var ritmSysId = current.sysapproval.sys_id;
var ritmVariables1 = '';
var ritmVariables2 = '';
var count = 0;
var ritm_val = new GlideRecord('sc_req_item');
ritm_val.get(ritmSysId);
var set = new GlideappVariablePoolQuestionSet();
set.setRequestID(ritmSysId);
set.load();
var vs1 = set.getFlatQuestions();
template.print('<table border="1px solid black">');
template.print("<tr>");
template.print("<td>" + "<strong>" + "Request Number" + "</strong>" + "</td>");
template.print("<td>" + '<a href="https://' + gs.getProperty('instance_name') + '.service-now.com/nav_to.do?uri=sc_req_item.do?sys_id=' + ritm_val.sys_id + '">' + ritm_val.getDisplayValue("number") + '</a>' +"</td>");
template.print("</tr>");
template.print("<tr>");
template.print("<td>" + "<strong>" + "Catalog Item:" + "</strong>" + "</td>");
template.print("<td>" + ritm_val.getDisplayValue("cat_item") + "</td>");
template.print("</tr>");
template.print("<tr>");
template.print("<td>" + "<strong>" + "Description:" + "</strong>" + "</td>");
template.print("<td>" + ritm_val.getDisplayValue("short_description") + "</td>");
template.print("</tr>");
template.print("<tr>");
template.print("<td>" + "<strong>" + "Cost:" + "</strong>" + "</td>");
template.print("<td>" + coststringO + '<br>' + coststringR + "</td>");
template.print("</tr>");
template.print("<tr>");
template.print("<td>" + "<strong>" + "Quantity:" + "</strong>" + "</td>");
template.print("<td>" + ritm_val.getDisplayValue("quantity") + "</td>");
template.print("</tr>");
for (var i = 0; i < vs1.size(); i++) {
if (count < 10) {
if (vs1.get(i).getLabel() != '' && JSUtil.notNil(vs1.get(i).getDisplayValue()) && vs1.get(i).getDisplayValue() != 'false' && vs1.get(i).isVisibleSummary() && vs1.get(i).getDisplayValue() != '--None--' && vs1.get(i).getDisplayValue() != null && vs1.get(i).getDisplayValue() != undefined) {
ritmVariables1 = '<b>' + vs1.get(i).getLabel() + '</b>:';
ritmVariables2 = vs1.get(i).getDisplayValue() + '<br>';
template.print("<tr>");
template.print("<td>" + ritmVariables1 + "</td>");
template.print("<td>" + ritmVariables2 + "</td>");
template.print("</tr>");
count++;
}
} else {
break;
}
}
})(current, template, email, email_action, event);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-11-2023 07:20 AM
Hmm, nothing there either. Can you try adding a div around the mail script and see if that helps?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-24-2024 09:02 AM - edited ‎07-24-2024 11:28 AM
GL!