Stop inbound action from creating an incident if another incident was created within certain time

maria03
Tera Contributor

We have a system triggering emails when something fails and we create an incident in ServiceNow. The problem is that the system tries multiple times to accomplish the task triggering emails each time that fails creating multiple incidents in ServiceNow within minutes. How can i stop the creation of duplicate incidents in ServiceNow (The other system doesn't have a way to stop triggering the emails).

 

Thanks,

Maria

3 REPLIES 3

Amit Gujarathi
Giga Sage
Giga Sage

Hi @maria03 ,
I trust you are doing fine.
We have a system triggering emails when something fails and we create an incident in ServiceNow. The problem is that the system tries multiple times to accomplish the task triggering emails each time that fails creating multiple incidents in ServiceNow within minutes. How can i stop the creation of duplicate incidents in ServiceNow (The other system doesn't have a way to stop triggering the emails).

// Get the email subject and description from the email
var emailSubject = 'Example Subject';
var emailDescription = 'Example Description';

// Query for existing incidents with the same subject and description
var incidentGr = new GlideRecord('incident');
incidentGr.addQuery('short_description', emailSubject);
incidentGr.addQuery('description', emailDescription);
incidentGr.query();

// If an incident already exists, do not create a new one
if (incidentGr.next()) {
  gs.info('Incident already exists with number: ' + incidentGr.number);
} else {
  // Create a new incident with the email details
  var newIncident = new GlideRecord('incident');
  newIncident.short_description = emailSubject;
  newIncident.description = emailDescription;
  newIncident.insert();
  gs.info('New incident created with number: ' + newIncident.number);
}

Was this answer helpful?


Please consider marking it correct or helpful.


Your feedback helps us improve!


Thank you!


Regards,


Amit Gujrathi



Sandeep Rajput
Tera Patron
Tera Patron

@maria03 I am assuming your inbound email script is having some logic to fetch short description and description from the email body. Before creating a new incident, your script should query the incident table and check if an incident with the same short description (since repetitive emails are getting generated assuming the short description for such incidents would be similar as well) already exist and if the record found was created within last X minutes. If any record is returned with this query then you need not to create an incident else if no records are found then a new incident can be created.

 

Hope this helps.

Slava Savitsky
Giga Sage

Use a GlideRecord query against the Incident table to check if an incident already exists and if that is the case, prevent the inbound action from creating a new one using the following code:

current.setAbortAction(true);