Email scrip to exclude a few variables
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2024 06:07 AM
Hello community!!
I have an email script that pulls all variables into an approval notification body. It works great :). I am having trouble excluding some variables from the print. Does the community see any issue with this script? I've tried to exclude a few different ways but it continues to print. Here is what I have:
template.print('<table border="1" cellspacing="0" cellpadding="4">');
template.print('<thead><tr>');
template.print('<th colspan="2">Summary of Requested item:</th>');
template.print('</tr></thead>');
template.print('<tbody>');
var gr = new GlideRecord("sc_req_item");
gr.addQuery("sys_id", current.sysapproval);
gr.query();
while (gr.next()) {
template.print('<tr>');
template.print('<td>RITM Number:</td>');
template.print('<td>' + gr.number + '</td>');
template.print('</tr>');
template.print('<tr>');
template.print('<td>Item:</td>');
template.print('<td>' + gr.cat_item.getDisplayValue() + '</td>');
template.print('</tr>');
template.print('<tr>');
template.print('<td colspan="2">Item Overview:</td>');
template.print('</tr>');
// Initialize the variable pool to get variables associated with the RITM, including variable sets
var variablePool = new GlideappVariablePoolQuestionSet();
variablePool.setRequestID(gr.sys_id);
variablePool.load();
var questions = variablePool.getFlatQuestions();
for (var i = 0; i < questions.size(); i++) {
var question = questions.get(i);
var label = question.getLabel();
var dval = question.getDisplayValue();
// Directly exclude specific variables within the print statement
if (label && dval) {
template.print(
label !== 'alternate_phone' &&
label !== 'email' &&
label !== 'location' ?
'<tr><td>' + label + ':</td><td>' + dval + '</td></tr>' : ''
);
}
}
}
template.print('</tbody>');
template.print('</table>');
1 REPLY 1

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2024 12:51 PM
Try this:
template.print('<table border="1" cellspacing="0" cellpadding="4">');
template.print('<thead><tr>');
template.print('<th colspan="2">Summary of Requested item:</th>');
template.print('</tr></thead>');
template.print('<tbody>');
var gr = new GlideRecord("sc_req_item");
gr.addQuery("sys_id", current.sysapproval);
gr.query();
while (gr.next()) {
template.print('<tr>');
template.print('<td>RITM Number:</td>');
template.print('<td>' + gr.number + '</td>');
template.print('</tr>');
template.print('<tr>');
template.print('<td>Item:</td>');
template.print('<td>' + gr.cat_item.getDisplayValue() + '</td>');
template.print('</tr>');
template.print('<tr>');
template.print('<td colspan="2">Item Overview:</td>');
template.print('</tr>');
// Initialize the variable pool to get variables associated with the RITM, including variable sets
var variablePool = new GlideappVariablePoolQuestionSet();
variablePool.setRequestID(gr.sys_id);
variablePool.load();
var questions = variablePool.getFlatQuestions();
for (var i = 0; i < questions.size(); i++) {
var question = questions.get(i);
var label = question.getLabel();
var dval = question.getDisplayValue();
// Directly exclude specific variables within the print statement
if (label && dval) {
if (label != 'alternate_phone' && label != 'email' && label != 'location') {
template.print('<tr><td>' + label + ':</td><td>' + dval + '</td></tr>');
}
}
}
}
template.print('</tbody>');
template.print('</table>');