Email is not displaying the content if called in notification written on HR task table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-15-2025 08:16 AM
(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template, /* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action, /* Optional GlideRecord */ event) { // Add your code here var parentHrService = current.parent.hr_service; //Fetching the current HR case Hrservice var currentHrService = current.hr_service;
//Storing hr service value in hr_Service var hr_service=parentHrService ? parentHrService : currentHrService; //Getting the value of New Hire onboarding1 Hr service sysID var onboardingHrService = gs.getProperty('sn_hr_le.passport_onboarding_hr_service'); //Getting the value of Leaver offboarding sysID var offboardingHrService = gs.getProperty('sn_hr_le.passport_offboarding_hr_service'); //Getting the value of Standard leaver Offboarding SysID var standardleaver = gs.getProperty('passport_standardLeaverOffboarding_hrservice'); //Getting the value of Subject person name from parent hrc if notification is on Hr Task table, else getting it from current HR case. var subjectPerson = (current.parent && current.parent.subject_person.name) ? current.parent.subject_person.name : current.subject_person.name; tableHTML += '<table style="margin: 0cm 45pt 12pt; font-size: 11pt; font-family: Calibri, sans-serif; width: 600px;">'; tableHTML += ' <tbody>'; tableHTML += ' <tr style="padding-bottom: 10px;">'; tableHTML += ' <th style="text-align: left; font-family: Arial, Helvetica, sans-serif; font-size: 12pt;white-space: nowrap;">Employee</th>'; tableHTML += ' <td style="font-family: Arial, Helvetica, sans-serif; font-size: 12pt;">:</td>'; tableHTML += ' <td style="font-family: Arial, Helvetica, sans-serif; font-size: 12pt;white-space: nowrap;">' + subjectPerson + '</td>'; tableHTML += ' </tr>'; tableHTML+='</body>'; tableHTML+='</table>';
template.print(tableHTML);
It is displaying on hr case table but not on hr task table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-17-2025 08:02 PM
Hello @NikhilEtikala,
-
Notification Content:Ensure the "Notification Content" field in the notification template correctly references the fields containing the called-in notification content.
-
Data Retrieval:Use the appropriate syntax to access the data from the parent HR case or related tables using GlideRecord or script. For example, if the content is in the "Description" field of the HR case, use
<hrCaseReference>.description
. -
Variables:If the content is stored in a variable, ensure you access it correctly using
<hrCaseReference>.variables.<variable_name>
. -
Rich Description:Verify that you are using the
rich_description
field and not the standarddescription
field, as the latter might not be rendered correctly in email notifications.
- Recipient Email Address: Verify that the recipient's email address is correct and active in the ServiceNow user record.
- Notification Status: Ensure the notification is enabled for the recipient in the user record.
- Email Server Configuration: Verify that the email server is configured correctly and that the system can send emails.
-
Preview:Use the "Notification Preview" feature to test the notification and ensure it displays the correct content before sending it.
-
Test Users:Send the notification to a test user and verify the email is received and contains the expected content.
-
System Logs:Check the system logs (System Logs > Emails) for any errors or issues related to sending the email.
-
Dynamic Content:If the content is dynamic (e.g., based on user input or system events), ensure the notification template is updated accordingly.
-
ACLs:Check for any Access Control Lists (ACLs) that might be restricting access to the necessary fields or records.
-
Event-Based Notifications:If the notification is triggered by an event, ensure the event is correctly configured and that the notification is associated with the event.If it is helpful, please mark it as helpful and accept the correct solution. By referring to this solution, it will be helpful to them.Thanks & Regards,Abbas Shaik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-17-2025 08:42 PM
Hello @NikhilEtikala ,
The issue with your email notification not displaying content on the HR Task table (`sn_hr_core_task`) is due to an uninitialized `tableHTML` variable and incorrect HTML syntax in the mail script. Below is a corrected script to display the subject person’s name in the email.
Corrected Mail Script
(function runMailScript(current, template, email, email_action, event) {
try {
var tableHTML = '';
var subjectPerson = (current.parent?.subject_person?.name) || (current.subject_person?.name) || 'Unknown';
tableHTML += '<table style="margin: 0 45pt 12pt; font-size: 11pt; font-family: Calibri, sans-serif; width: 600px;">';
tableHTML += '<tbody><tr style="padding-bottom: 10px;">';
tableHTML += '<th style="text-align: left; font-family: Arial, Helvetica, sans-serif; font-size: 12pt; white-space: nowrap;">Employee</th>';
tableHTML += '<td style="font-family: Arial, Helvetica, sans-serif; font-size: 12pt;">:</td>';
tableHTML += '<td style="font-family: Arial, Helvetica, sans-serif; font-size: 12pt; white-space: nowrap;">' + subjectPerson + '</td>';
tableHTML += '</tr></tbody></table>';
template.print(tableHTML);
} catch (e) {
gs.error('Mail Script Error: ' + e);
template.print('Error generating email content.');
}
})(current, template, email, email_action, event);
Fixes Applied
1. Initialized `tableHTML` to avoid undefined errors.
2. Fixed HTML: Changed `</body>` to `</tbody>`.
3. Simplified `subjectPerson` logic with a fallback (`'Unknown'`) for null values.
4. Removed unused variables (e.g., `hr_service`).
5. Added error handling.
Steps to Test
1. Update the notification’s mail script with this code.
2. Test with an HR Task record, ensuring `subject_person` is set in `current` or `parent`.
3. Use "Notification Preview" or send to a test user.
4. Check email logs (`System Logs > Emails`) for issues.
5. For debugging, add `gs.info('Subject Person: ' + subjectPerson);` and check `System Logs > All`.
If the issue persists, please share any error logs or confirm if `subject_person` is populated. Let me know if you need help with additional logic, like `hr_service`
Thanks,
Karthik