MRVS Data not getting displayed in array format in the notification

shalinihorak
Tera Contributor

 

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.

 

(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,sc_req_item) {
var rec = new GlideRecord(sc_req_item);
if(rec.get(sys_id)) {
return rec.getDisplayValue();
}
}
})(current, template, email, email_action, event);
2 ACCEPTED SOLUTIONS

Ankur Bawiskar
Tera Patron
Tera Patron

@shalinihorak 

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.

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

View solution in original post

anshul_goyal
Kilo Sage

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

View solution in original post

12 REPLIES 12

shalinihorak
Tera Contributor

The MRVS array should display in the below format in the notification which is not happening.

Ankur Bawiskar
Tera Patron
Tera Patron

@shalinihorak 

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.

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

anshul_goyal
Kilo Sage

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

@anshul_goyal 

Seems you copied the same script which I already shared above.

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