I have to add all detail in table format in notification
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-03-2025 04:14 AM
Hi,
I have to add all detail in table format in notification. When request is submitted for 'ABC' then it should send notification to group and it contain all detail in table format which is available in request submitted.
When request is submitted it is storing request value in table('Visitor') parent and child table('Visitor Registration') and I want to take value from both table and need to send in notification. When email sent to user then it contain two table format in one table it contain value stored in Visitor table for submitted request and in other table it contain value for Visitor registration table for request submitted.
Please see attached screenshot :
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-03-2025 06:51 AM - edited 08-03-2025 06:56 AM
You’ll write the email body using Scripted HTML and GlideRecord queries (like in your code).
But as per best practice you can use Mail Script for better reusability:
Use below code in you mail script: name - visitor_details_mail_script
(function runMailScript(current, template, email, email_action, event) {
var html = '';
html += '<h2>Visitor Request Summary</h2>';
html += '<table border="1"><tr><th>Short Description</th><th>Location</th><th>Host</th></tr>';
html += '<tr><td>' + current.short_description + '</td>';
html += '<td>' + current.location.getDisplayValue() + '</td>';
html += '<td>' + current.host.getDisplayValue() + '</td></tr></table>';
html += '<h2>Visitor Registrations</h2>';
html += '<table border="1"><tr><th>First Name</th><th>Last Name</th><th>Company</th></tr>';
var reg = new GlideRecord('sn_wsd_visitor_visitor_registration');
reg.addQuery('source_visit', current.sys_id);
reg.query();
while (reg.next()) {
html += '<tr><td>' + reg.first_name + '</td><td>' + reg.last_name + '</td><td>' + reg.company + '</td></tr>';
}
html += '</table>';
template.print(html);
})(current, template, email, email_action, event);
and then call above in you notification body:
${mail_script:visitor_details_mail_script}
if this works then plz mark helpful and access as a solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-03-2025 09:15 AM - edited 08-03-2025 09:21 AM
Hi @niveditakumari ,
Good day !!
Please create notification email script and attach that to your notification...
Name your script as - visitor_details_table
(function runMailScript(current, template, email, email_action, event) {
template.print("<h2>Visitor Request Summary</h2>");
template.print("<table border='1' cellpadding='4' cellspacing='0' style='border-collapse:collapse; width:100%;'>");
template.print("<tr><th>Short Description</th><th>Location</th><th>Host</th></tr>");
template.print("<tr><td>" + (current.short_description || "") + "</td>");
template.print("<td>" + (current.location.getDisplayValue() || "") + "</td>");
template.print("<td>" + (current.host.getDisplayValue() || "") + "</td></tr>");
template.print("</table>");
template.print("<h2>Visitor Registration Details</h2>");
template.print("<table border='1' cellpadding='4' cellspacing='0' style='border-collapse:collapse; width:100%;'>");
template.print("<tr><th>First Name</th><th>Last Name</th><th>Company</th><th>External?</th></tr>");
var reg = new GlideRecord("sn_wsd_visitor_visitor_registration");
reg.addQuery("source_visit", current.sys_id);
reg.query();
while (reg.next()) {
template.print("<tr>");
template.print("<td>" + reg.first_name.getDisplayValue() + "</td>");
template.print("<td>" + reg.last_name.getDisplayValue() + "</td>");
template.print("<td>" + reg.company.getDisplayValue() + "</td>");
template.print("<td>" + (reg.visitor_external ? "Yes" : "No") + "</td>");
template.print("</tr>");
}
template.print("</table>");
})(current, template, email, email_action, event);
Go to your notification as paste this script [ ${mail_script:visitor_details_table} ] wherever you want your table details to be shown...
Kaushal Kumar Jha - ServiceNow Consultant - Lets connect on Linkedin: https://www.linkedin.com/in/kaushalkrjha/