
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-18-2023 01:03 PM
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-18-2023 01:43 PM
Hello @sarahjantz
Ihaven't had the chance to test it yet, but you can give it a try. I made a minor correction in the script. Please verify and test if it resolves the issue.
(function runMailScript(current, template, email, email_action, event) {
// Retrieve the RITM record
var grReq = new GlideRecord('sc_req_item');
if (grReq.get('sys_id', current.sysapproval)) {
// Loop through the variables of the RITM
for (var i in grReq.variables) {
if (grReq.variables[i]) {
template.print(getQuestionLabel(i) + ": " + grReq.variables[i].getDisplayValue() + "<br/>");
}
}
}
// Function to get the question label for a variable
function getQuestionLabel(question) {
var getVar = new GlideRecord('item_option_new');
getVar.addQuery('name', question);
getVar.query();
if (getVar.next()) {
return getVar.question_text;
}
}
// Attach links for any attachments
attachLinks();
// Function to attach links for attachments
function attachLinks() {
var grAttachment = new GlideRecord('sys_attachment');
grAttachment.addQuery('table_sys_id', current.sysapproval.sys_id);
grAttachment.query();
if (grAttachment.hasNext()) {
template.print("Attachments: <br/>");
while (grAttachment.next()) {
var attachLink = generateAttachmentLink(grAttachment);
template.print(attachLink + "<br/>");
}
template.print("<hr/>");
}
}
// Function to generate an attachment link
function generateAttachmentLink(attachment) {
return '<a href="' + gs.generateURL(attachment.getTableName(), attachment.sys_id) + '">' + attachment.file_name + '</a>';
}
})(current, template, email, email_action, event);
Let me know your views on this and Mark ✅Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.
Regards,
Aniket
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-18-2023 01:43 PM
Hello @sarahjantz
Ihaven't had the chance to test it yet, but you can give it a try. I made a minor correction in the script. Please verify and test if it resolves the issue.
(function runMailScript(current, template, email, email_action, event) {
// Retrieve the RITM record
var grReq = new GlideRecord('sc_req_item');
if (grReq.get('sys_id', current.sysapproval)) {
// Loop through the variables of the RITM
for (var i in grReq.variables) {
if (grReq.variables[i]) {
template.print(getQuestionLabel(i) + ": " + grReq.variables[i].getDisplayValue() + "<br/>");
}
}
}
// Function to get the question label for a variable
function getQuestionLabel(question) {
var getVar = new GlideRecord('item_option_new');
getVar.addQuery('name', question);
getVar.query();
if (getVar.next()) {
return getVar.question_text;
}
}
// Attach links for any attachments
attachLinks();
// Function to attach links for attachments
function attachLinks() {
var grAttachment = new GlideRecord('sys_attachment');
grAttachment.addQuery('table_sys_id', current.sysapproval.sys_id);
grAttachment.query();
if (grAttachment.hasNext()) {
template.print("Attachments: <br/>");
while (grAttachment.next()) {
var attachLink = generateAttachmentLink(grAttachment);
template.print(attachLink + "<br/>");
}
template.print("<hr/>");
}
}
// Function to generate an attachment link
function generateAttachmentLink(attachment) {
return '<a href="' + gs.generateURL(attachment.getTableName(), attachment.sys_id) + '">' + attachment.file_name + '</a>';
}
})(current, template, email, email_action, event);
Let me know your views on this and Mark ✅Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.
Regards,
Aniket

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2023 03:52 PM
Hello Aniket,
Thank you for the quick response. This worked!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2023 09:21 PM
Hello @sarahjantz ,
Welcome & Glad to hear that it worked 😁