Adding values from a multi row variable set to an email notification

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2024 09:35 PM
I am trying to add the values from a multi row variable set and I'm just not having any luck.
I've had a look at these:
- how to show variable set values in notification - ServiceNow Community
- Solved: Display Multi row variable set columns in notifica... - Page 3 - ServiceNow Community
The one I've tried is:
How to Display Multi Row Variable set (MRVS) data... - ServiceNow Community
My MRVS is as follows:
Internal Name: other_items
Type: Multi Row
Layout: 1 Column Wide
I only have one variable within the MRVS
Name: other_options
Type: Single Line Text
My current mail script is:
(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */
email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */
event) {
// This sets the font size and type
var mrvs = current.variables.other_items; // MRVS Internal name
var rowCount = mrvs.getRowCount();
if (rowCount >= 1) {
template.print("<table border =1>");
template.print("<tr>");
template.print("<th>Others</th>");
template.print("</tr>");
for (var i = 0; i < rowCount; i++) {
template.print("<tr>");
var row = mrvs.getRow(i);
template.print("<td>" + getName(row.others.toString(),'current.variables.other_options') + "</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);
All it is returning is the table border and heading, no variable values
What am I missing.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2024 09:39 PM
Hi @Bidduam ,
I trust you are doing great.
Here's a revised version of your mail script:
(function runMailScript(current, template, email, email_action, event) {
// Accessing the MRVS field
var mrvs = current.variables.other_items; // MRVS Internal name
// Checking if MRVS has any rows
if (mrvs) {
var rows = mrvs.split('\n'); // Splitting the MRVS into individual rows
// Checking if there are rows to process
if (rows.length > 0) {
template.print("<table border='1'>");
template.print("<tr>");
template.print("<th>Other Options</th>");
template.print("</tr>");
// Iterating through each row
rows.forEach(function(row) {
var otherOptions = row.split(':'); // Splitting each row into fields
var otherOption = otherOptions[0]; // Accessing the value of the 'other_options' field
// Printing each other option value in a table row
template.print("<tr>");
template.print("<td>" + otherOption + "</td>");
template.print("</tr>");
});
template.print("</table>");
}
}
})(current, template, email, email_action, event);
Was this answer helpful?
Please consider marking it correct or helpful.
Your feedback helps us improve!
Thank you!
Regards,
Amit Gujrathi

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2024 10:31 PM - edited 02-20-2024 10:43 PM
Thank you for the revised mail script, but when I've replaced mine with yours it now does show anything at all, even the table border and heading is no longer appearing.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2024 09:41 PM
Hi there,
Here an older article of mine which you can also use for notifications:
- 2021-05-20 - Article - Creating records or a summary from Multi-Row Variable Set (2)
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2024 10:46 PM
Thank you for the link. I'm not totally sure what I need to change in order to use it for what I'm wanting.
Presumably all I need is from the last description part?