- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2025 11:45 PM
Hello All ,
There is a requirement to display Variable Information in Approval Notifications for a Record Producer submitted in a Scoped Application, so for that we are using this email script somehow it is working , But variable details are showing up duplicate.
This is the script we use :
This is the approval notification but there are duplicate variables are showing up, Please guide.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2025 04:40 AM
Glad to know that my script worked fine.
To hide false values enhance as this
I added this extra condition in the IF
&& tbl_obj.variables[key].getDisplayValue() != 'false'
(function runMailScript(current, template, email, email_action, event) {
// Add your code here
if (current.source_table == "x_tmms7_finance_finance_ticket") {
template.print("Summary of Finance Ticket ");
}
template.print('<table border="1">');
var tbl_obj = new GlideRecord('x_tmms7_finance_finance_ticket');
tbl_obj.get('sys_id', current.sysapproval);
// Use a Set to track processed variables
var processedVariables = new Set();
for (var key in tbl_obj.variables) {
if (tbl_obj.variables[key] && !processedVariables.has(key) && tbl_obj.variables[key].getDisplayValue() != 'false') {
template.print("<tr>");
template.print("<td>" + getQuestionLabel(key) + "</td>\r\n");
template.print("<td>" + tbl_obj.variables[key].getDisplayValue() + "</td>\r\n");
template.print("</tr>");
// Mark this variable as processed
processedVariables.add(key);
}
}
template.print("</table>");
function getQuestionLabel(question) {
var vara = new GlideRecord('item_option_new');
vara.addQuery('name', question);
vara.query();
if (vara.next()) {
return vara.question_text;
}
return question;
}
})(current, template, email, email_action, event);
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2025 01:29 AM
@Ankur Bawiskar Could you Guide me on that ? Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2025 01:44 AM
I don't see any duplicate in your screenshots
but still you can try this
(function runMailScript(current, template, email, email_action, event) {
// Add your code here
if (current.source_table == "x_tmms7_finance_finance_ticket") {
template.print("Summary of Finance Ticket ");
}
template.print('<table border="1">');
var tbl_obj = new GlideRecord('x_tmms7_finance_finance_ticket');
tbl_obj.get('sys_id', current.sysapproval);
// Use a Set to track processed variables
var processedVariables = new Set();
for (var key in tbl_obj.variables) {
if (tbl_obj.variables[key] && !processedVariables.has(key)) {
template.print("<tr>");
template.print("<td>" + getQuestionLabel(key) + "</td>\r\n");
template.print("<td>" + tbl_obj.variables[key].getDisplayValue() + "</td>\r\n");
template.print("</tr>");
// Mark this variable as processed
processedVariables.add(key);
}
}
template.print("</table>");
function getQuestionLabel(question) {
var vara = new GlideRecord('item_option_new');
vara.addQuery('name', question);
vara.query();
if (vara.next()) {
return vara.question_text;
}
return question;
}
})(current, template, email, email_action, event);
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2025 04:29 AM - edited 06-04-2025 07:11 AM
Thank you for the script , I used that script and it is working , Is it possible to hide the variables which are visible as false [Those are not checked on the form ] ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2025 04:40 AM
Glad to know that my script worked fine.
To hide false values enhance as this
I added this extra condition in the IF
&& tbl_obj.variables[key].getDisplayValue() != 'false'
(function runMailScript(current, template, email, email_action, event) {
// Add your code here
if (current.source_table == "x_tmms7_finance_finance_ticket") {
template.print("Summary of Finance Ticket ");
}
template.print('<table border="1">');
var tbl_obj = new GlideRecord('x_tmms7_finance_finance_ticket');
tbl_obj.get('sys_id', current.sysapproval);
// Use a Set to track processed variables
var processedVariables = new Set();
for (var key in tbl_obj.variables) {
if (tbl_obj.variables[key] && !processedVariables.has(key) && tbl_obj.variables[key].getDisplayValue() != 'false') {
template.print("<tr>");
template.print("<td>" + getQuestionLabel(key) + "</td>\r\n");
template.print("<td>" + tbl_obj.variables[key].getDisplayValue() + "</td>\r\n");
template.print("</tr>");
// Mark this variable as processed
processedVariables.add(key);
}
}
template.print("</table>");
function getQuestionLabel(question) {
var vara = new GlideRecord('item_option_new');
vara.addQuery('name', question);
vara.query();
if (vara.next()) {
return vara.question_text;
}
return question;
}
})(current, template, email, email_action, event);
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader