sending email after 30 minutes

Deepika54
Tera Contributor

Hello experts,

 

In our incident table, incidents are getting created. If it has been more than 30 mins and no incident has been created, i need to trigger an email. Can anyone help me in this requirement. Thanks in advance.

1 ACCEPTED SOLUTION

Rahul Kumar17
Tera Guru

Hi Deepika,

 

To trigger an email if no incident has been created in the incident table for more than 30 minutes, you can create a scheduled job with a script that checks the last incident creation time and sends an email if it exceeds the specified threshold. Here's an example script you can use:

 

// Set the time threshold in minutes
var timeThreshold = 30;

// Get the incident table
var incidentTable = new GlideRecord('incident');

// Set the query to get incidents created in the last 30 minutes
var now = new GlideDateTime();
now.addMinutes(-timeThreshold);
incidentTable.addQuery('sys_created_on', '>=', now);
incidentTable.query();

// If no incidents were created in the last 30 minutes, send an email
if (!incidentTable.hasNext()) {
gs.eventQueue("email.send", current, "Sender", "recipient@example.com", "No incidents created in the last " + timeThreshold + " minutes", "No incidents have been created in the incident table in the last " + timeThreshold + " minutes. Please investigate.");
}

 

To create a scheduled job with this script, follow these steps:

  1. Navigate to the "Scheduled Jobs" module in ServiceNow.
  2. Click "New" to create a new scheduled job.
  3. Enter a name for the job, such as "Incident Creation Monitor".
  4. Set the "Run" field to a desired interval, such as every 15 minutes.
  5. In the "Script" field, copy and paste the script provided above.
  6. Modify the "timeThreshold" variable to your desired time limit in minutes.
  7. Save the scheduled job.

Once this scheduled job is active, it will run at the specified interval and check if any incidents have been created in the last 30 minutes. If no incidents have been created, it will send an email to the specified recipient with the specified message. You can modify the email message to include additional information as needed.

 

Thanks,

Rahul Kumar

If my response helped please mark it correct and close the thread.

Thanks,
Rahul Kumar

View solution in original post

2 REPLIES 2

Rahul Kumar17
Tera Guru

Hi Deepika,

 

To trigger an email if no incident has been created in the incident table for more than 30 minutes, you can create a scheduled job with a script that checks the last incident creation time and sends an email if it exceeds the specified threshold. Here's an example script you can use:

 

// Set the time threshold in minutes
var timeThreshold = 30;

// Get the incident table
var incidentTable = new GlideRecord('incident');

// Set the query to get incidents created in the last 30 minutes
var now = new GlideDateTime();
now.addMinutes(-timeThreshold);
incidentTable.addQuery('sys_created_on', '>=', now);
incidentTable.query();

// If no incidents were created in the last 30 minutes, send an email
if (!incidentTable.hasNext()) {
gs.eventQueue("email.send", current, "Sender", "recipient@example.com", "No incidents created in the last " + timeThreshold + " minutes", "No incidents have been created in the incident table in the last " + timeThreshold + " minutes. Please investigate.");
}

 

To create a scheduled job with this script, follow these steps:

  1. Navigate to the "Scheduled Jobs" module in ServiceNow.
  2. Click "New" to create a new scheduled job.
  3. Enter a name for the job, such as "Incident Creation Monitor".
  4. Set the "Run" field to a desired interval, such as every 15 minutes.
  5. In the "Script" field, copy and paste the script provided above.
  6. Modify the "timeThreshold" variable to your desired time limit in minutes.
  7. Save the scheduled job.

Once this scheduled job is active, it will run at the specified interval and check if any incidents have been created in the last 30 minutes. If no incidents have been created, it will send an email to the specified recipient with the specified message. You can modify the email message to include additional information as needed.

 

Thanks,

Rahul Kumar

If my response helped please mark it correct and close the thread.

Thanks,
Rahul Kumar

Hi Deepika,

Thank you for marking my response as helpful.

If my response helped please mark it correct and close the thread.

Thanks,
Rahul Kumar

If my response helped please mark it correct and close the thread.

Thanks,
Rahul Kumar