- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-25-2023 11:37 AM - edited 08-25-2023 11:38 AM
Hey guys,
I have this approval email template that uses a mail script. I need to tweak this mail script a tiny bit to show "opened by" user's name right above requested for" name.
I'm a javascript noob so by looking at the code, what I can think of is that GlideappVariablePoolQuestionSet() is retrieving all the variable inputs from the requested_item and "opened by" is not among those variables so I can't print it using the same script (I could be wrong here btw).
right now my email notification looks like this;
".....
details of the request:
requested for: xxx
request type: xxx
full_name: xxxx
........."
my expected output is this;
".....
details of the request:
opened by: xxx
requested for: xxx
request type: xxx
full_name: xxxx
........."
here's the mail script that I'm trying to edit.
(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */
email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */
event) {
var item = new GlideRecord("sc_req_item");
if (current.getTableName() == "sysapproval_approver") {
item.addQuery("sys_id", current.sysapproval.sys_id);
} else {
item.addQuery("sys_id", current.sys_id);
}
item.query();
while (item.next()) {
template.print('<strong>' + item.cat_item.getDisplayValue() + '</strong>'+ "<br />" +"<br />");
template.print(" details of this request:<br />");
var keys = new Array();
var set = new GlideappVariablePoolQuestionSet();
set.setRequestID(item.sys_id);
set.load();
var vs = set.getFlatQuestions();
for (var i = 0; i < vs.size(); i++) {
if (vs.get(i).getLabel() != '') {
if ( vs.get(i).getDisplayValue() != "" ) {
template.space(4);
template.print('<strong>' + vs.get(i).getLabel() + " : "+'</strong>' + vs.get(i).getDisplayValue() + "<br />");
}
}
}
template.print("<br/><strong>Cost:</strong> " + item.price.getDisplayValue());
}
})(current, template, email, email_action, event);
Any help is appreciated! 🙂
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-25-2023 11:43 AM
Hi Sam,
(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */
email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */
event) {
var item = new GlideRecord("sc_req_item");
if (current.getTableName() == "sysapproval_approver") {
item.addQuery("sys_id", current.sysapproval.sys_id);
} else {
item.addQuery("sys_id", current.sys_id);
}
item.query();
while (item.next()) {
template.print('<strong>' + item.cat_item.getDisplayValue() + '</strong>'+ "<br />" +"<br />");
template.print(" details of this request:<br />");
template.print('<strong>' + "Opened by : "+'</strong>' + item.opened_by.getDisplayValue()+ "<br />");
var keys = new Array();
var set = new GlideappVariablePoolQuestionSet();
set.setRequestID(item.sys_id);
set.load();
var vs = set.getFlatQuestions();
for (var i = 0; i < vs.size(); i++) {
if (vs.get(i).getLabel() != '') {
if ( vs.get(i).getDisplayValue() != "" ) {
template.space(4);
template.print('<strong>' + vs.get(i).getLabel() + " : "+'</strong>' + vs.get(i).getDisplayValue() + "<br />");
}
}
}
template.print("<br/><strong>Cost:</strong> " + item.price.getDisplayValue());
}
})(current, template, email, email_action, event);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-25-2023 11:43 AM
Hi Sam,
(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */
email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */
event) {
var item = new GlideRecord("sc_req_item");
if (current.getTableName() == "sysapproval_approver") {
item.addQuery("sys_id", current.sysapproval.sys_id);
} else {
item.addQuery("sys_id", current.sys_id);
}
item.query();
while (item.next()) {
template.print('<strong>' + item.cat_item.getDisplayValue() + '</strong>'+ "<br />" +"<br />");
template.print(" details of this request:<br />");
template.print('<strong>' + "Opened by : "+'</strong>' + item.opened_by.getDisplayValue()+ "<br />");
var keys = new Array();
var set = new GlideappVariablePoolQuestionSet();
set.setRequestID(item.sys_id);
set.load();
var vs = set.getFlatQuestions();
for (var i = 0; i < vs.size(); i++) {
if (vs.get(i).getLabel() != '') {
if ( vs.get(i).getDisplayValue() != "" ) {
template.space(4);
template.print('<strong>' + vs.get(i).getLabel() + " : "+'</strong>' + vs.get(i).getDisplayValue() + "<br />");
}
}
}
template.print("<br/><strong>Cost:</strong> " + item.price.getDisplayValue());
}
})(current, template, email, email_action, event);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-25-2023 11:51 AM
this worked! thanks Jaspal.
can you confirm if my assumption was correct?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-25-2023 11:52 AM
Hello @Sam10 ,
Kindly Update the code as mentioned below.
(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */
email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */
event) {
var item = new GlideRecord("sc_req_item");
if (current.getTableName() == "sysapproval_approver") {
item.addQuery("sys_id", current.sysapproval.sys_id);
} else {
item.addQuery("sys_id", current.sys_id);
}
item.query();
while (item.next()) {
template.print('<strong>' + item.cat_item.getDisplayValue() + '</strong>'+ "<br />" +"<br />");
template.print(" details of this request:<br />");
template.print(" Opened by: "+ item.opened_by.getDisplayValue() +"<br />");
var keys = new Array();
var set = new GlideappVariablePoolQuestionSet();
set.setRequestID(item.sys_id);
set.load();
var vs = set.getFlatQuestions();
for (var i = 0; i < vs.size(); i++) {
if (vs.get(i).getLabel() != '') {
if ( vs.get(i).getDisplayValue() != "" ) {
template.space(4);
template.print('<strong>' + vs.get(i).getLabel() + " : "+'</strong>' + vs.get(i).getDisplayValue() + "<br />");
}
}
}
template.print("<br/><strong>Cost:</strong> " + item.price.getDisplayValue());
}
})(current, template, email, email_action, event);