- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2025 11:23 AM
Hello,
I'm here after following the ticket Solved: Approval Email Display RITM Ticket Variables - Fol... - ServiceNow Community
1. But this script is not following the UI catalog policies to display what the user had submitted within the ESC to display email variables. I think it's showing whatever variable is not empty during the submission of the catalog form. for example, if variable "A" of checkbox type is not checked still the value is showing "A: false " in the approval email.
2. Not displaying label type variables. Not displaying a file which is attached in the attachment variable.
Could anyone please help in figuring out the solution for the above issues.
email script used:
(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */
email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */
event) {
var item_sys_id;
var tableName = current.getTableName();
if(tableName == 'sysapproval_approver'){
item_sys_id = current.sysapproval;
} else if (tableName == 'sc_task'){
item_sys_id = current.request_item.sys_id;
} else if(tableName == 'sc_req_item'){
item_sys_id = current.sys_id;
} else{
item_sys_id ='';
}
//gs.log("SYS ID : "+item_sys_id);
var item = new GlideRecord("sc_req_item");
item.addQuery("sys_id", item_sys_id);
item.query();
while (item.next()) {
template.print("<div style='font-size:12pt;font-family:Arial, Helvetica, sans-serif;'><span><b>Options</b>:</span><br />");
var keys = [];
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() != '') { //This displays all of the variables (answered/unanswered)
var val = vs.get(i).getDisplayValue();
if (val != '') {
template.space(4);
template.print(vs.get(i).getLabel() + " : " + val + "<br />");
}
}
}
template.print("</div>");
}
// Add your code here
})(current, template, email, email_action, event);
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-02-2025 05:57 AM
really difficult to determine in email script whether variable was hidden on form during catalog submission
So it's not possible
Doesn't make sense in showing Label type variable as it doesn't hold information
Doesn't logically fit to show the attachment variable info in email
You can enhance the script to show only non empty variables and checkbox with true value
(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */
email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */
event) {
var item_sys_id;
var tableName = current.getTableName();
if(tableName == 'sysapproval_approver'){
item_sys_id = current.sysapproval;
} else if (tableName == 'sc_task'){
item_sys_id = current.request_item.sys_id;
} else if(tableName == 'sc_req_item'){
item_sys_id = current.sys_id;
} else{
item_sys_id ='';
}
//gs.log("SYS ID : "+item_sys_id);
var item = new GlideRecord("sc_req_item");
item.addQuery("sys_id", item_sys_id);
item.query();
while (item.next()) {
template.print("<div style='font-size:12pt;font-family:Arial, Helvetica, sans-serif;'><span><b>Options</b>:</span><br />");
var keys = [];
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() != '') { //This displays all of the variables (answered/unanswered)
var val = vs.get(i).getDisplayValue();
if (val != '' && val != 'false') {
template.space(4);
template.print(vs.get(i).getLabel() + " : " + val + "<br />");
}
}
}
template.print("</div>");
}
// Add your code here
})(current, template, email, email_action, event);
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-02-2025 05:57 AM
really difficult to determine in email script whether variable was hidden on form during catalog submission
So it's not possible
Doesn't make sense in showing Label type variable as it doesn't hold information
Doesn't logically fit to show the attachment variable info in email
You can enhance the script to show only non empty variables and checkbox with true value
(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */
email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */
event) {
var item_sys_id;
var tableName = current.getTableName();
if(tableName == 'sysapproval_approver'){
item_sys_id = current.sysapproval;
} else if (tableName == 'sc_task'){
item_sys_id = current.request_item.sys_id;
} else if(tableName == 'sc_req_item'){
item_sys_id = current.sys_id;
} else{
item_sys_id ='';
}
//gs.log("SYS ID : "+item_sys_id);
var item = new GlideRecord("sc_req_item");
item.addQuery("sys_id", item_sys_id);
item.query();
while (item.next()) {
template.print("<div style='font-size:12pt;font-family:Arial, Helvetica, sans-serif;'><span><b>Options</b>:</span><br />");
var keys = [];
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() != '') { //This displays all of the variables (answered/unanswered)
var val = vs.get(i).getDisplayValue();
if (val != '' && val != 'false') {
template.space(4);
template.print(vs.get(i).getLabel() + " : " + val + "<br />");
}
}
}
template.print("</div>");
}
// Add your code here
})(current, template, email, email_action, event);
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-03-2025 10:09 AM
Hello @Ankur Bawiskar ,
Thank you for your response, is there any way i can at least download the attachment directly from the approval email which user attached in the catalog form using RITM attachment variable? currently it is showing attachment name only.
Thank you!
Thank You!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-03-2025 06:51 PM
you can include the actual file in the approval email but for that you will have to use custom solution to copy that file from variable to RITM to Approval
OR
include link to sys_attachment in the email so that user can click and once logins to instance can download
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-03-2025 11:30 PM
Hello @Ankur Bawiskar ,
Could you please help me in the code as per your first suggestion for files. Thank you for your help.
(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */
email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */
event) {
var item_sys_id;
var tableName = current.getTableName();
if(tableName == 'sysapproval_approver'){
item_sys_id = current.sysapproval;
} else if (tableName == 'sc_task'){
item_sys_id = current.request_item.sys_id;
} else if(tableName == 'sc_req_item'){
item_sys_id = current.sys_id;
} else{
item_sys_id ='';
}
//gs.log("SYS ID : "+item_sys_id);
var item = new GlideRecord("sc_req_item");
item.addQuery("sys_id", item_sys_id);
item.query();
while (item.next()) {
template.print("<div style='font-size:12pt;font-family:Arial, Helvetica, sans-serif;'><span><b>Options</b>:</span><br />");
var keys = [];
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() != '') { //This displays all of the variables (answered/unanswered)
var val = vs.get(i).getDisplayValue();
if (val != '' && val != 'false') {
template.space(4);
template.print(vs.get(i).getLabel() + " : " + val + "<br />");
}
}
}
template.print("</div>");
}
// Add your code here
})(current, template, email, email_action, event);