MRVS row.getDisplayValue() not returning choice label in Mail Script notification
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago - last edited an hour ago
Hi all,
I'm trying to display Multi Row Variable Set (MRVS) data in an email notification using a Mail Script, so that i can display th value on my email notification.
(function runMailScript(current, template, email, email_action, event) {
var mrvs = current.variables.select_your_destination_s;
var rowCount = mrvs.getRowCount();
for (var i = 0; i < rowCount; i++) {
var row = mrvs.getRow(i);
template.print(row.getDisplayValue('destination') + " - " + row.getDisplayValue('preference') + "<br>");
}
})(current, template, email, email_action, event);
it s not returning anything but when i do row.destination it shows the value of the field , for example here it shows FOR, the value of the field not the displayed text
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
this is expected out of the box behavior, it will always give value and not Label
try this to get display value i.e. Choice Label instead of Choice Value
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 10x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
an hour ago - last edited 41m ago
Hi @ghitabahaj ,
I’m not aware of a direct method to get the MVRS choice display values, but we can achieve this using GlideRecord by querying the question_choice table.
var mrvs = current.variables.select_your_destination_s;
var choiceMap = {};
var choiceGR = new GlideRecord('question_choice');
choiceGR.addQuery('question', 'IN', 'comma separated sysids of questions');
choiceGR.query();
while (choiceGR.next()) {
var questionName = choiceGR.question.name.toString();
if (!choiceMap[questionName]) {
choiceMap[questionName] = {};
}
choiceMap[questionName][choiceGR.value.toString()] = choiceGR.text.toString();
}
var rowCount = mrvs.getRowCount();
for (var i = 0; i < rowCount; i++) {
var row = mrvs.getRow(i);
var dest = choiceMap.destination[row.destination] || row.destination;
var pref = choiceMap.preference[row.preference] || row.preference;
template.print(dest + " - " + pref + "<br>");
}
Store the Question sysid's in a system property