Change Management E-Mail Notification
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2025 01:19 PM - edited 01-14-2025 01:23 PM
Good Afternoon - I would like to create an email notification which will send out hourly the list of open changes over the weekend but when I create the message I can only get it to add 1 record to it when I select the field. How to I get it to show the whole list of changes which are still open (not executed) during the time frame of Friday afternoon to Sunday AM.
When it fires off - it will only show one Change and not the whole list of changes which meet these conditions. How do you get it to show all of them?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2025 10:37 PM
Could you please share your configurations/notification emails scripts that you have done to check this further?
Mark this as Helpful / Accept the Solution if this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2025 10:42 PM
Hello @Matt_EpiQ
First you should have a scheduled job which will be triggered hourly basis and if condition is met it will trigger event, which will be associated with your custom notification over change request table. In this notification through a mail script, you can get list of all records as per your requirement and put down over table using HTML.
Your scheduled Job script can be as below:
var now = new GlideDateTime();
var dayOfWeek = now.getDayOfWeek(); // 1 = Monday, 7 = Sunday
var hourOfDay = now.getHourOfDay(); // 0 = Midnight, 23 = 11 PM
// Check if it's between Saturday 12 AM and Monday 12 AM
if ((dayOfWeek == 6) || // Saturday
(dayOfWeek == 7) || // Sunday
(dayOfWeek == 1 && hourOfDay < 12)) { // Monday morning before 12 AM
// Trigger an event
gs.eventQueue('custom.open_changes_notification', null, now, null);
}
While the email notification script can be as below:
var emailBody = '<table border="1" style="width:100%; border-collapse: collapse;">';
emailBody += '<tr><th>Change Number</th><th>Short Description</th><th>State</th><th>Assignment Group</th></tr>';
var gr = new GlideRecord('change_request');
gr.addQuery('state', '!=', 'Closed');
gr.addQuery('state', '!=', 'Cancel');
gr.query();
while (gr.next()) {
emailBody += '<tr>';
emailBody += '<td>' + gr.number + '</td>';
emailBody += '<td>' + gr.short_description + '</td>';
emailBody += '<td>' + gr.state.getDisplayValue() + '</td>';
emailBody += '<td>' + gr.assignment_group.getDisplayValue() + '</td>';
emailBody += '</tr>';
}
emailBody += '</table>';
template.print(emailBody);
Note - Script condition can vary as per your requirement, this is just to gain some idea how to proceed with your blocker.
If my response has helped you hit helpful button and if your concern is solved do mark my response as correct.
Thanks & Regards
Viraj Hudlikar.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2025 10:50 PM
how have you configured it currently?
please share that so that we can help
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-16-2025 01:59 PM
I haven't gotten anything to work yet and am going to try Viraj's sample to see if that works - new at scripting