- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-02-2025 02:52 AM
Hi,
I have a requirement to display task(for ex sc_task) short desc and assigned to in email body for custom application. There will be two task. Need to display both(task1 & task2) short desc and assigned to if it is closed complete state. Notification will be on parent table(for ex sc_req_item). Is it achievable from email script?
Thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-02-2025 03:31 AM
you will have to use email script for this as notification is on RITM table
something like this in email script to show in tabular format but please enhance
(function runMailScript(current, template, email, email_action, event) {
// Add your code here
// Email script for sc_req_item notification - HTML table format
var taskGR = new GlideRecord('sc_task');
taskGR.addQuery('request_item', current.sys_id); // Link to parent sc_req_item
taskGR.addQuery('state', '3'); // 3 = Closed Complete (adjust if needed)
taskGR.query();
var output = '';
output += '<table border="1" cellpadding="4" cellspacing="0" style="border-collapse:collapse;">';
output += '<tr>';
output += '<th>Task Short Description</th>';
output += '<th>Assigned To</th>';
output += '</tr>';
var found = false;
while (taskGR.next()) {
found = true;
output += '<tr>';
output += '<td>' + taskGR.short_description + '</td>';
output += '<td>' + (taskGR.assigned_to ? taskGR.assigned_to.getDisplayValue() : 'Not Assigned') + '</td>';
output += '</tr>';
}
output += '</table>';
if (!found) {
template.print('No closed complete tasks found for this request item.');
}
template.print(output); // The table will be rendered in the email body
})(current, template, email, email_action, event);
Without tabular format
(function runMailScript(current, template, email, email_action, event) {
// Add your code here
// Email script for sc_req_item notification
// Get all related sc_task records
var taskGR = new GlideRecord('sc_task');
taskGR.addQuery('request_item', current.sys_id); // Link to parent sc_req_item
taskGR.addQuery('state', '3'); // 3 = Closed Complete (adjust if your state values are different)
taskGR.query();
var output = '';
while (taskGR.next()) {
output += '<b>Task:</b> ' + taskGR.short_description + '<br/>';
output += '<b>Assigned To:</b> ' + (taskGR.assigned_to ? taskGR.assigned_to.getDisplayValue() : 'Not Assigned') + '<br/><br/>';
}
if (!output) {
template.print('No closed complete tasks found for this request item.');
}
template.print(output); // This will be included in the email body
})(current, template, email, email_action, event);
It will print like this
Task: Approve hardware request
Assigned To: John Smith
Task: Configure laptop
Assigned To: Jane Doe
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
06-02-2025 03:03 AM
you can create a mail script that queries the records you need and use the mail script in your notification
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-02-2025 03:11 AM
how to return multiple values and call in notification?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-02-2025 03:31 AM
you will have to use email script for this as notification is on RITM table
something like this in email script to show in tabular format but please enhance
(function runMailScript(current, template, email, email_action, event) {
// Add your code here
// Email script for sc_req_item notification - HTML table format
var taskGR = new GlideRecord('sc_task');
taskGR.addQuery('request_item', current.sys_id); // Link to parent sc_req_item
taskGR.addQuery('state', '3'); // 3 = Closed Complete (adjust if needed)
taskGR.query();
var output = '';
output += '<table border="1" cellpadding="4" cellspacing="0" style="border-collapse:collapse;">';
output += '<tr>';
output += '<th>Task Short Description</th>';
output += '<th>Assigned To</th>';
output += '</tr>';
var found = false;
while (taskGR.next()) {
found = true;
output += '<tr>';
output += '<td>' + taskGR.short_description + '</td>';
output += '<td>' + (taskGR.assigned_to ? taskGR.assigned_to.getDisplayValue() : 'Not Assigned') + '</td>';
output += '</tr>';
}
output += '</table>';
if (!found) {
template.print('No closed complete tasks found for this request item.');
}
template.print(output); // The table will be rendered in the email body
})(current, template, email, email_action, event);
Without tabular format
(function runMailScript(current, template, email, email_action, event) {
// Add your code here
// Email script for sc_req_item notification
// Get all related sc_task records
var taskGR = new GlideRecord('sc_task');
taskGR.addQuery('request_item', current.sys_id); // Link to parent sc_req_item
taskGR.addQuery('state', '3'); // 3 = Closed Complete (adjust if your state values are different)
taskGR.query();
var output = '';
while (taskGR.next()) {
output += '<b>Task:</b> ' + taskGR.short_description + '<br/>';
output += '<b>Assigned To:</b> ' + (taskGR.assigned_to ? taskGR.assigned_to.getDisplayValue() : 'Not Assigned') + '<br/><br/>';
}
if (!output) {
template.print('No closed complete tasks found for this request item.');
}
template.print(output); // This will be included in the email body
})(current, template, email, email_action, event);
It will print like this
Task: Approve hardware request
Assigned To: John Smith
Task: Configure laptop
Assigned To: Jane Doe
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