MRVS row.getDisplayValue() not returning choice label in Mail Script notification

ghitabahaj
Tera Expert

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

 

 

 

2 REPLIES 2

Ankur Bawiskar
Tera Patron

@ghitabahaj 

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

(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.getCellDisplayValue() + " - " + row.getDisplayValue('preference') + "<br>");
    }
})(current, template, email, email_action, event);

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

NagaChandaE
Mega Sage

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