How to fetch Catalog task variables in email script for resquested item notification
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
Below script helped me to achieve this
(function runMailScript(current, template, email, email_action, event) {
// On sc_req_item, 'current' IS the Requested Item.
// We don't need a GlideRecord lookup for 'item'.
var closeNote = current.close_notes ? current.close_notes.getDisplayValue() : "";
var set = new GlideappVariablePoolQuestionSet();
set.setRequestID(current.sys_id); // Pass the RITM SysID here
set.load();
var vs = set.getFlatQuestions();
if (vs.size() > 0) {
template.print("<hr style='width: 98%;' /><p><b><u>Task Details</u></b></p>");
// Only print Close Notes if they aren't empty
if (closeNote) {
template.print("<p><b>Close Notes</b>: " + closeNote + "</p>");
}
for (var i = 0; i < vs.size(); i++) {
var variable = vs.get(i);
var label = variable.getLabel();
var displayValue = variable.getDisplayValue();
// Logic: Don't print empty variables or 'false' (empty checkboxes)
if (label && displayValue && displayValue != "" && displayValue != "false") {
template.print("<p><b>" + label + "</b>: " + displayValue + "</p>");
}
}
}
})(current, template, email, email_action, event);
Thanks,
Raj
