help on Email script

William08
Tera Contributor

Hi all,

 

I have a email script written but it is not displaying multi row variable but we want multi row variable to be displayed. Please help!

 

below is the script

(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
    /* Optional EmailOutbound */
    email, /* Optional GlideRecord */ email_action,
    /* Optional GlideRecord */
    event) {

    // Add your code here

    var id = current.document_id;
    var item = new GlideRecord("sc_req_item");
    item.addQuery("sys_id", id);
    item.query();
    while (item.next()) {

        var keys = new Array();
        var set = new GlideappVariablePoolQuestionSet();

        set.setRequestID(item.sys_id);

        set.load();

        var vs = set.getFlatQuestions();
        if (vs.size() == '0' || vs.size() == '') {
            return;
        } else {
            template.print("<hr style='width: 98%;' /><p><b><u>Requested Item Variables:</u></b></p>");

            for (var i = 0; i < vs.size(); i++) {        

if(vs.get(i).getLabel() != "Show NASSA Common Info" && vs.get(i).getLabel() != "New Hire Type"){


                  if (vs.getLabel() != "" && vs.getDisplayValue() != "" && vs.getDisplayValue() != 'false' && vs.get(i).getDisplayValue() != 'false' && vs.get(i).getDisplayValue() != '') {


                        template.print("<p><b>" + vs.get(i).getLabel() + "</b>: " + vs.get(i).getDisplayValue() + "</p>");
                    }
                }
            
        }
		}



    }



})(current, template, email, email_action, event);

 

Thanks

3 REPLIES 3

Prince Arora
Tera Sage
Tera Sage

@William08 

 

I got the same requirement few days back, I have handled it using making a table in HTML as below

 

As MVRS is returning the data in JSON format

 

 

var data = current.variables.NAME_OF_THE_MVRS;

var headers = "<tr>";

var finalR = "";

var str = "<table style='border:1px solid black;'><tr>";

 

for (var i = 0; i < data.length; i++) {

            var rows = "<tr style='border:1px solid black;'>";

            var obj = data[i];

            for (var key in obj) {

                if (i == 0) {

                    headers = headers + "<td>" + key + "</td>";

                }

                rows = rows + "<td>" + obj[key] + "</td>";

     }

rows = rows + "</tr>";

            finalR = finalR + rows;

        }

        str = str + headers + "</tr>" + finalR + "</table>";

        template.print(str);

}

 

This is just an idea, please modify the code according to your requirement 

 

Please mark it helpful or Accept the solution if it works for you!!

Hi @Prince Arora,

 

This email script should pick mvrs on its own we cannot specify the mvrs name is there is anything we can do

 

@William08 

 

Nope I don't think so its possible

 

But you can do something like this:

 

var gr = new GlideRecord("io_set_item");
gr.addEncodedQuery("variable_set.titleINPQR,ABC,MNO^sc_cat_item=" + current.cat_item);
gr.query();
if (gr.next()) {
var data = "";
switch (gr.variable_set.internal_name + "") {
case "pqr":
data = current.variables.pqr;
break;
case "abc":
data = current.variables.abc;
break;
case "mno":
data = current.variables.mno;
break;
}

 

If my answer solved your issue, please mark my answer as  Correct & 👍Helpful based on the Impact.