help on Email script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-10-2023 07:27 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-10-2023 07:51 AM - edited 11-10-2023 07:51 AM
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!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-10-2023 08:13 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-10-2023 09:57 AM
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.