Notification for Send-ready type

Kri
Tera Guru

I need to trigger a notification if sys_email table type contains 'Send-ready' state for more than an hour.

2 ACCEPTED SOLUTIONS

Rajesh Chopade1
Mega Sage

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

View solution in original post

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

View solution in original post

4 REPLIES 4

Robbie
Kilo Patron
Kilo Patron

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

it is for multiple records. I need to get notify during such interruption

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

Rajesh Chopade1
Mega Sage

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