Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to get Display Value of the variable in a Multi Row Variable set (MRVS) in a email script.

venkatanathansp
Tera Contributor

Hello!

I was looking for some help with figuring out the lines needed in an email script to display the value of  variable in a multi row variable set. This is the code which iam using. Its returning the backend value. I am not able to use the get_display_value(). 

 

 

var mrvs = current.variables.stored_items; \\internal name of MRVS
    var rowCount = mrvs.getRowCount();
   
    if (rowCount >= 1) {

        template.print("<table border =1>");
        template.print("<tr>");
        template.print("<th>Item</th>");
       template.print("<th>Device Type</th>");
        template.print("</tr>");

        for (var i = 0; i < rowCount; i++) {
            template.print("<tr>");
            var row = mrvs.getRow(i);
            template.print("<td>"+ row.item +"</td>"); // item - internal name of variable (Select Box)
            template.print("<td>" + row.device_type + "</td>"); // device_type - internal name of variable  (Select Box)
            template.print("</tr>");
        }
        template.print("</table>");
1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@venkatanathansp 

you won't get it like that

try this

var mrvs = current.variables.stored_items;\\
internal name of MRVS
var rowCount = mrvs.getRowCount();

if (rowCount >= 1) {

    template.print("<table border =1>");
    template.print("<tr>");
    template.print("<th>Item</th>");
    template.print("<th>Device Type</th>");
    template.print("</tr>");

    for (var i = 0; i < rowCount; i++) {
        template.print("<tr>");
        var row = mrvs.getRow(i);
        var questionValue1 = ''; // give sysId of the item variable

        var dv = new GlideRecord('question_choice');
        dv.addQuery('question', questionValue1); // change questionValue with the question's sys_id
        dv.addQuery('value', row.item);
        dv.query();
        if (dv.next()) {
            template.print("<td>" + dv.text + "</td>"); // item - internal name of variable (Select Box)
        }

        var questionValue2 = ''; // give sysId of the device type variable
        var dv1 = new GlideRecord('question_choice');
        dv1.addQuery('question', questionValue2);
        dv1.addQuery('value', row.device_type);
        dv1.query();
        if (dv1.next()) {
            template.print("<td>" + dv1.text + "</td>");
        }
        template.print("</tr>");
    }
    template.print("</table>");

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

View solution in original post

2 REPLIES 2

NabeelJ
Tera Expert

You can get the label of the variable in the variable set with this code:

var now_GR = new GlideRecord('sc_req_item');
now_GR.get('02c38dcd87013300e0ef0cf888cb0bb2');

var vars = now_GR.variables.getElements(true);

for (var i=0; i<vars.length; i++) {
    var now_V = vars[i];
    if (now_V.isMultiRow()) {
        var rows = now_V.getRows();
        for (var j=0; j<now_V.getRowCount(); j++) {
            var row = rows[j];
            var cells = row.getCells();
            for (var k=0; k<cells.length; k++) {
                var cell = cells[k];
                gs.info(cell.getLabel() + ":" + cell.getCellDisplayValue())
            }
        }
    }
}

 
Let me know if this helped.

Ankur Bawiskar
Tera Patron
Tera Patron

@venkatanathansp 

you won't get it like that

try this

var mrvs = current.variables.stored_items;\\
internal name of MRVS
var rowCount = mrvs.getRowCount();

if (rowCount >= 1) {

    template.print("<table border =1>");
    template.print("<tr>");
    template.print("<th>Item</th>");
    template.print("<th>Device Type</th>");
    template.print("</tr>");

    for (var i = 0; i < rowCount; i++) {
        template.print("<tr>");
        var row = mrvs.getRow(i);
        var questionValue1 = ''; // give sysId of the item variable

        var dv = new GlideRecord('question_choice');
        dv.addQuery('question', questionValue1); // change questionValue with the question's sys_id
        dv.addQuery('value', row.item);
        dv.query();
        if (dv.next()) {
            template.print("<td>" + dv.text + "</td>"); // item - internal name of variable (Select Box)
        }

        var questionValue2 = ''; // give sysId of the device type variable
        var dv1 = new GlideRecord('question_choice');
        dv1.addQuery('question', questionValue2);
        dv1.addQuery('value', row.device_type);
        dv1.query();
        if (dv1.next()) {
            template.print("<td>" + dv1.text + "</td>");
        }
        template.print("</tr>");
    }
    template.print("</table>");

If my response helped please mark it correct and close the thread so that it benefits future readers.

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