Unable to skip, hide, or prevent unchecked checkbox variables from being printed in email summary
Community Alums
Not applicable
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2025 06:32 AM - edited 01-07-2025 07:07 AM
Hi Expert,
I have created an email script for an order guide containing 12 catalog items. After all the RITMs are closed as "Complete," a notification is triggered for a group. While everything is functioning correctly, the email summary includes unchecked checkboxes, which I want to exclude. I have tried several approaches, but none have worked. Please see the attached file and email script. If anyone knows how to remove unchecked checkboxes from the summary, please let me know. Thank You!
Email Script:
(function runMailScript(current, template, email, email_action, event) {
// Function to get RITM variables and their values, including MRVS
function getRITMVariables(ritm) {
var variables = [];
var variableSet = new GlideappVariablePoolQuestionSet();
variableSet.setRequestID(ritm.sys_id);
variableSet.load();
var vs = variableSet.getFlatQuestions();
for (var k = 0; k < vs.size(); k++) {
var value = vs.get(k).getDisplayValue();
var type = vs.get(k).getType();
// Skip checkbox variables with a value of "false"
if (type === 'boolean' && value === 'false') {
continue;
}
variables.push({
label: vs.get(k).getLabel(),
value: value || "Not Provided", // Default to "Not Provided" if the value is empty
type: type,
rows: vs.get(k).getRows ? vs.get(k).getRows() : [] // MRVS rows if available
});
}
return variables;
}
// Function to print MRVS rows
function printMRVSRows(rows, template) {
for (var k = 0; k < rows.length; k++) {
var row = rows[k];
for (var field in row) {
// Print all MRVS rows, including those with "Not Provided" values
template.print("<tr><td colspan='2'>" + field + ": " + (row[field] || "Not Provided") + "</td></tr>");
}
}
}
// Start the table
template.print("<table border='1'><tr><th>RITM Number</th><th>Catalog Item</th><th>Variable</th><th>Value</th></tr>");
// Query sc_req_item records related to the current approval request
var gr = new GlideRecord('sc_req_item');
gr.addQuery("request", current.sys_id);
gr.query();
// Iterate through each RITM in the query result
while (gr.next()) {
// Store RITM numbers and catalog item names
var ritmNumber = gr.number.getDisplayValue();
var catalogItem = gr.cat_item.getDisplayValue();
var variables = getRITMVariables(gr);
// Filter out variables with "Not Provided" values
variables = variables.filter(function (variable) {
return variable.value !== "Not Provided";
});
// Print RITM number and catalog item name, with rowspan for variables
template.print("<tr><td rowspan='" + Math.max(1, variables.length) + "'>" + ritmNumber + "</td>");
template.print("<td rowspan='" + Math.max(1, variables.length) + "'>" + catalogItem + "</td>");
// Loop through variables and print them
if (variables.length > 0) {
for (var j = 0; j < variables.length; j++) {
template.print("<td>" + variables[j].label + "</td>");
template.print("<td>" + variables[j].value + "</td></tr>");
// If the variable is a multi-row variable (MRVS), print the rows
if (variables[j].type === 'multi_row' && variables[j].rows.length > 0) {
printMRVSRows(variables[j].rows, template);
}
}
} else {
// If no variables are available, print a placeholder row
template.print("<td colspan='2'>No variables to display</td></tr>");
}
// Check for MRVS data using the mrvsfetch class if needed
var objFncs = new global.mrvsfetch();
var mrvsTable = objFncs.getMRVSFormated(gr.sys_id);
// If MRVS data is found, print it under the RITM's variable table
if (mrvsTable) {
template.print("<tr><td colspan='4'>" + mrvsTable + "</td></tr>");
gs.log('MRVS data printed for RITM: ' + gr.sys_id);
} else {
gs.log('No MRVS data found for RITM: ' + gr.sys_id);
}
}
// Close the table
template.print("</table>");
})(current, template, email, email_action, event);
0 REPLIES 0