- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2025 02:08 AM
We are trying to display MRVS data in tabular format in the notification which is created once the catalog item is submitted.We are facing issue with displaying the MRVS value captured for field "Please select which pair" in array format (comma separated values as shown in the screenshot) in the notification. We have created notification email script for the same. It is not working as expected.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2025 02:19 AM
try this
Note: give correct table name which is being referred by that list collector.
I think it's u_instrument and not u_instrument_list, but please check from your end once
(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */
email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */
event) {
var mrvs = current.variables.please_specify_which_pairs_the_client_wants_to_move; // MRVS Internal name
var mrvsJSON = JSON.parse(current.variables.please_specify_which_pairs_the_client_wants_to_move);
var rowCount = mrvs.getRowCount();
var rowCountJSON = mrvsJSON.getRowCount();
if (rowCount >= 1) {
template.print("<br<b>Pairs the client wants to move</b>");
template.print("<table border = 1>");
template.print("<tr>");
template.print("<th>please select which pairs</th>");
template.print("<th>new tier session</th>");
template.print("<th>current tier session</th>");
template.print("</tr>");
for (var i = 0; i < rowCount; i++) {
template.print("<tr>");
var row = mrvs.getRow(i);
template.print("<td>" + getName(row.please_select_which_pair_add.toString(), 'u_instrument_list') + "</td>");
template.print("<td>" + row.new_tier_session_add + "</td>");
template.print("<td>" + row.current_tier_session_add + "</td>");
template.print("</tr>");
}
template.print("</table>");
}
function getName(sys_id, tableName) {
var arr = [];
var rec = new GlideRecord(tableName);
rec.addQuery('sys_id', 'IN', sys_id);
rec.query();
while (rec.next()) {
arr.push(rec.getDisplayValue());
}
return arr.toString():
}
})(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
08-01-2025 02:31 AM
Hi @shalinihorak,
sc_req_item itself is a table in ServiceNow, please change the parameter/argument name in the getName function. Use Below code:
(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */
email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */
event) {
var mrvs = current.variables.please_specify_which_pairs_the_client_wants_to_move; // MRVS Internal name
var mrvsJSON = JSON.parse(current.variables.please_specify_which_pairs_the_client_wants_to_move);
var rowCount = mrvs.getRowCount();
var rowCountJSON = mrvsJSON.getRowCount();
if (rowCount >= 1) {
template.print("<br<b>Pairs the client wants to move</b>");
template.print("<table border = 1>");
template.print("<tr>");
template.print("<th>please select which pairs</th>");
template.print("<th>new tier session</th>");
template.print("<th>current tier session</th>");
template.print("</tr>");
for (var i = 0; i < rowCount; i++) {
template.print("<tr>");
var row = mrvs.getRow(i);
template.print("<td>" + getName(row.please_select_which_pair_add.toString(), 'u_instrument_list') + "</td>");
template.print("<td>" + row.new_tier_session_add + "</td>");
template.print("<td>" + row.current_tier_session_add + "</td>");
template.print("</tr>");
}
template.print("</table>");
}
function getName(sys_id, tableName) {
var arr = [];
var rec = new GlideRecord(tableName);
rec.addQuery('sys_id', 'IN', sys_id);
rec.query();
while (rec.next()) {
arr.push(rec.getDisplayValue());
}
return arr.toString():
}
})(current, template, email, email_action, event);
Please mark my response as Accepted and Helpful for future references.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2025 02:14 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2025 02:19 AM
try this
Note: give correct table name which is being referred by that list collector.
I think it's u_instrument and not u_instrument_list, but please check from your end once
(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */
email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */
event) {
var mrvs = current.variables.please_specify_which_pairs_the_client_wants_to_move; // MRVS Internal name
var mrvsJSON = JSON.parse(current.variables.please_specify_which_pairs_the_client_wants_to_move);
var rowCount = mrvs.getRowCount();
var rowCountJSON = mrvsJSON.getRowCount();
if (rowCount >= 1) {
template.print("<br<b>Pairs the client wants to move</b>");
template.print("<table border = 1>");
template.print("<tr>");
template.print("<th>please select which pairs</th>");
template.print("<th>new tier session</th>");
template.print("<th>current tier session</th>");
template.print("</tr>");
for (var i = 0; i < rowCount; i++) {
template.print("<tr>");
var row = mrvs.getRow(i);
template.print("<td>" + getName(row.please_select_which_pair_add.toString(), 'u_instrument_list') + "</td>");
template.print("<td>" + row.new_tier_session_add + "</td>");
template.print("<td>" + row.current_tier_session_add + "</td>");
template.print("</tr>");
}
template.print("</table>");
}
function getName(sys_id, tableName) {
var arr = [];
var rec = new GlideRecord(tableName);
rec.addQuery('sys_id', 'IN', sys_id);
rec.query();
while (rec.next()) {
arr.push(rec.getDisplayValue());
}
return arr.toString():
}
})(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
08-01-2025 02:31 AM
Hi @shalinihorak,
sc_req_item itself is a table in ServiceNow, please change the parameter/argument name in the getName function. Use Below code:
(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */
email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */
event) {
var mrvs = current.variables.please_specify_which_pairs_the_client_wants_to_move; // MRVS Internal name
var mrvsJSON = JSON.parse(current.variables.please_specify_which_pairs_the_client_wants_to_move);
var rowCount = mrvs.getRowCount();
var rowCountJSON = mrvsJSON.getRowCount();
if (rowCount >= 1) {
template.print("<br<b>Pairs the client wants to move</b>");
template.print("<table border = 1>");
template.print("<tr>");
template.print("<th>please select which pairs</th>");
template.print("<th>new tier session</th>");
template.print("<th>current tier session</th>");
template.print("</tr>");
for (var i = 0; i < rowCount; i++) {
template.print("<tr>");
var row = mrvs.getRow(i);
template.print("<td>" + getName(row.please_select_which_pair_add.toString(), 'u_instrument_list') + "</td>");
template.print("<td>" + row.new_tier_session_add + "</td>");
template.print("<td>" + row.current_tier_session_add + "</td>");
template.print("</tr>");
}
template.print("</table>");
}
function getName(sys_id, tableName) {
var arr = [];
var rec = new GlideRecord(tableName);
rec.addQuery('sys_id', 'IN', sys_id);
rec.query();
while (rec.next()) {
arr.push(rec.getDisplayValue());
}
return arr.toString():
}
})(current, template, email, email_action, event);
Please mark my response as Accepted and Helpful for future references.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2025 02:41 AM
Seems you copied the same script which I already shared above.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader