- 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 04:40 AM
@Ankur Bawiskar, I had already written the same script in my PDI, which might be why it seems familiar and you're thinking it's the same.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2025 04:46 AM
No worries, just a suggestion please make sure the script you post is different and in case before posting if you see similar script is already posted then avoid posting.
This avoids confusion with the person who asked question.
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 04:50 AM
@Ankur Bawiskar, Thank you for understanding. I’ll keep that in mind moving forward. I’d also like to kindly request that you give others, including myself, a chance to contribute as well. You're responding quite quickly, and I also aspire to become a rising star and actively contribute here.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2025 04:57 AM
Sure.
Keep learning and sharing.
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:56 AM
@Ankur Bawiskar @anshul_goyal Thank you for the response.
