Display Multi Row Variable set Data in a Approval Notification
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2023 06:20 AM
Hi All,
There is a custom table which is similar to RITM that is called Automated Requests. One of the form has MRVS data which needs to be included in the approval notification when it is requested.
By using this blog()https://www.servicenow.com/community/developer-articles/how-to-display-multi-row-variable-set-mrvs-d...), I'm able to populate the MRVS in the Notification in a tabular format. The issue I'm facing is when I preview the notification, it is working on the Automated Request table but the Notification is not working on Approver table, so I have created a event on GBS Request table and created a BR on Approver table which triggers the event but it is not working.
Can anyone please suggest how we can achieve this on the Approval notification which is on custom table.
TIA
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2023 07:23 AM
you might have to tweak the script based on which table the notification is present.
On your custom approval table which field refers to RITM etc?
Use that in script
Something like this
(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */
email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */
event) {
var gr = new GlideRecord("sc_req_item");
gr.addQuery("sys_id", current.u_field);
gr.query();
if (gr.next()) {
// Fetch the MRVS data and display them as table in notification
template.print("<br>Name: " + gr.variables.full_name);
template.print("<br>Date of Birth: " + gr.variables.date_of_birth);
var mrvs = gr.variables.employment_history; // MRVS Internal name
var rowCount = mrvs.getRowCount();
if (rowCount >= 1) {
template.print("<br<b>Employment Details</b>");
template.print("<table border =1>");
template.print("<tr>");
template.print("<th>Company</th>");
template.print("<th>Designation</th>");
template.print("<th>Start Date</th>");
template.print("<th>End Date</th>");
template.print("<th>Location</th>");
template.print("</tr>");
for (var i = 0; i < rowCount; i++) {
template.print("<tr>");
var row = mrvs.getRow(i);
template.print("<td>" + getName(row.company.toString(),'core_company') + "</td>");
template.print("<td>" + row.designation + "</td>");
template.print("<td>" + row.start_date + "</td>");
template.print("<td>" + row.end_date + "</td>");
template.print("<td>" + getName(row.location.toString(),'cmn_location') + "</td>");
template.print("</tr>");
}
template.print("</table>");
}
}
//This function accept sys_id and table and returns the Display name.
function getName(sys_id,tblName) {
var rec = new GlideRecord(tblName);
if(rec.get(sys_id)) {
return rec.getDisplayValue();
}
}
})(current, template, email, email_action, event);
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-21-2023 04:03 AM
Hi Ankur, what do you do for Select box variable. It does not works as expected.