- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2024 03:26 AM - edited 08-16-2024 03:04 AM
I need to trigger a notification if sys_email table type contains 'Send-ready' state for more than an hour.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2024 04:21 AM
Hi @Kri
You can achieve it by creating scheduled job on 'sys_email' table for records with 'Send-ready' and that state for more than an hour.
Following sample script you can use in your scheduled job.
var emailGR = new GlideRecord('sys_email');
// Get the current date and time
var currentTime = new GlideDateTime();
// Subtract one hour from the current time to set the threshold
currentTime.addHoursUTC(-1);
// Add a query to find records with "send-ready" type older than one hour
emailGR.addQuery('type', 'send-ready');
emailGR.addQuery('sys_created_on', '<=', currentTime);
emailGR.query();
// Check if there are any matching records
if (emailGR.hasNext()) {
// Construct a message or handle notification logic here
var message = 'The following emails are in "Send-ready" state for more than an hour:\n\n';
while (emailGR.next()) {
// Append details of each email to the message
message += 'Email Subject: ' + emailGR.subject + '\n';
message += 'Created On: ' + emailGR.sys_created_on.getDisplayValue() + '\n\n';
}
// Send a notification (replace 'notification_name' with your notification name)
// Event to trigger a notification
gs.eventQueue('custom.send_ready_notification', emailGR, message, '');
}
You can add run time as per your requirement.
I hope my answer helps you to resolve your issue, if yes please mark my answer helpful & correct.
thank you
rajesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2024 04:27 AM
Hi @Kri,
So click on the 'Execute now' button in the SMTP Sender scheduled job as advised in my earlier response.
That will kick the job off.
To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Kudos.
Thanks, Robbie
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2024 03:53 AM
Hi @Kri,
Is it only a single email record that is stuck in 'send-ready' or is there a number of records?
The job ('scheduled job') that controls the sending of emails is called: SMTP Sender.
It should execute every minute. To manually 'nudge' this, type 'Scheduled Jobs' into the Navigation menu and select the bottom link under 'System Scheduler'.
Search for the job called SMTP Sender and click on the 'Execute now' button
Additionally check the below link for trouble shooting emails from ServiceNow support.
To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Kudos.
Thanks, Robbie
https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0521382
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2024 04:10 AM
it is for multiple records. I need to get notify during such interruption
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2024 04:27 AM
Hi @Kri,
So click on the 'Execute now' button in the SMTP Sender scheduled job as advised in my earlier response.
That will kick the job off.
To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Kudos.
Thanks, Robbie
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2024 04:21 AM
Hi @Kri
You can achieve it by creating scheduled job on 'sys_email' table for records with 'Send-ready' and that state for more than an hour.
Following sample script you can use in your scheduled job.
var emailGR = new GlideRecord('sys_email');
// Get the current date and time
var currentTime = new GlideDateTime();
// Subtract one hour from the current time to set the threshold
currentTime.addHoursUTC(-1);
// Add a query to find records with "send-ready" type older than one hour
emailGR.addQuery('type', 'send-ready');
emailGR.addQuery('sys_created_on', '<=', currentTime);
emailGR.query();
// Check if there are any matching records
if (emailGR.hasNext()) {
// Construct a message or handle notification logic here
var message = 'The following emails are in "Send-ready" state for more than an hour:\n\n';
while (emailGR.next()) {
// Append details of each email to the message
message += 'Email Subject: ' + emailGR.subject + '\n';
message += 'Created On: ' + emailGR.sys_created_on.getDisplayValue() + '\n\n';
}
// Send a notification (replace 'notification_name' with your notification name)
// Event to trigger a notification
gs.eventQueue('custom.send_ready_notification', emailGR, message, '');
}
You can add run time as per your requirement.
I hope my answer helps you to resolve your issue, if yes please mark my answer helpful & correct.
thank you
rajesh