How to remove null filed in approval email
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 hours ago
Hi @everyone,
Could you please help me with remove null filed in Approval email, please check below snap
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
did you add gs.info() and debug at which iteration it's giving null?
Does your catalog item have MRVS inside it?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
please use item.variables.getElements() instead of getFlatQuestions()
updated script
template.print("Summary of Requested item:\n");
var item = new GlideRecord("sc_req_item");
item.addQuery("sys_id", current.sysapproval);
item.query();
while (item.next()) {
var nicePrice = item.price ? parseFloat(item.price).toFixed(2) : '';
template.print(item.number + ": " + item.cat_item.getDisplayValue() + (nicePrice ? " - $" + nicePrice : "") + "\n");
template.print(" Options:\n");
template.print("<table style='border-collapse: collapse; border-color: white; background-color: lightblue; width: 400px;' border='1' cellspacing='0' cellpadding='4'>");
template.print("<thead><tr style='background-color: #4CAF50; color: white;'><th style='padding: 8px;'>Item</th><th style='padding: 8px;'>Value</th></tr></thead>");
template.print("<tbody>");
var variables = item.variables.getElements();
var rowCount = 0;
for (var i = 0; i < variables.length; i++) {
var question = variables[i].getQuestion();
var label = question.getLabel();
var displayValue = question.getDisplayValue();
// Skip empty/null/false values or missing labels
if (!label || !displayValue || displayValue === "false" || displayValue === "") continue;
// Specific cat_items that always show variables
var specificCats = [
'cf2a3f204f0d2a006209ecee0210c7df',
'aa895f894f4acb0029160ad14210c70d',
'2f7aafc04f1dab80aca9e28d0210c743'
];
// Specific labels to always show
var specificLabels = [
"Contact name (If different from Requested By)",
"[Optional] Contact phone",
"Name (needs to be selected from the Service Catalog Home Page)",
"User ID",
"Region",
"Job Title",
"New IFF employee? (For rehire or relocation, choose No)",
"Location",
"Business Unit",
"Equivalent user",
"Requested For Name",
"Job Title",
"Requested By Name",
"Create new AD user",
"Frutarom File Server permissions",
"Please provide the File Server path",
"Frutarom HPM (Hyperion)",
"Frutarom EIS (Finance Reporting)",
"Justification for your access request:"
];
var showVar = specificCats.indexOf(item.cat_item.toString()) !== -1 ||
specificLabels.indexOf(label) !== -1 ||
current.wf_activity && current.wf_activity.name == 'Get manager approval';
if (showVar) {
// Handle multi-value (list collectors) - convert to bullet list if array
var formattedValue = displayValue;
if (displayValue.indexOf(',') !== -1) {
var values = displayValue.split(',').map(function(v) {
return v.trim();
});
formattedValue = values.join('<br>• ');
}
template.print("<tr style='border: 1px solid #ddd;'>");
template.print("<td style='padding: 8px; font-weight: bold; width: 50%;'>" + label + "</td>");
template.print("<td style='padding: 8px;'>" + formattedValue + "</td>");
template.print("</tr>");
rowCount++;
}
}
if (rowCount === 0) {
template.print("<tr><td colspan='2' style='padding: 12px; text-align: center; color: #666;'>No variables to display</td></tr>");
}
template.print("</tbody></table><br>");
}
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
Hi @Brahmi Pandla ,
NOTE: Before Trying below mail script save your old mail script and added comments where required.
Mail Script:
Please mark as helpful if this solves the issue.
Thanks
Yamsani Bhavani
