Prevent Inbound Email Action with same Subject and Created on less than 10 min
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-09-2015 12:46 PM
Hi All,
We are creating Incidents when a server sends an automatic reply for Alerts, and it is creating an Incident each time it receives an email from the server. NEW requirement is that Servicenow should avoid creating a NEW incident if the coming Email has SAME subject as an already existed Incident and the former one is created less than 10min ago. in other terms servicenow system should create a NEW incident if the comoing email has SAME subject as an already existed Incident and created >10min ago.
My Initial understanding is i have to query the Incident table and check for the SUMMARY which matches the coming Subject and match date on CREATED field with the current SYSTEM DATE and proceed either to avoid or create INCIDENT.
How to script these two conditions in Inbound Email Action?
thanks in advanced,
sry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-09-2015 01:52 PM
Seems like you should be able to script something like the below into an inbound email action? I haven't tested this, so it might need some tweaking. You'll want to order it so it comes before any actions that create an incident.
var gr = new GlideRecord('incident');
gr.addEncodedQuery('short_description=' + email.subject + '^sys_created_on>=javascript:gs.minutesAgoStart(10)');
gr.query();
// If I find an email with this subject in the last 10 minutes, stop.
if(gr.next()){
event.state = "stop_processing";
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2015 03:08 PM
Hi Dan,
sorry for the late reply and thank you so much for your prompt reply. The below i have tried but its not creating an incident when i tried,could you please where i am doing the mistake !!
var subject = email.subject.toLowerCase();
var sid = gs.createUser(email.from);
var emailTo = email.to.toLowerCase();
if(emailTo.indexOf("abc@xyz.com")>=0) {
var grInc = new GlideRecord('incident');
grInc.addEncodedQuery('short_description=' + subject + '^sys_created_on>=javascript:gs.minutesAgoStart(15)');
gr.query();
if(gr.next()) {
event.state = "stop_processing";
}
else {
current.caller_id = sid;
current.description = email.body_text;
current.short_description = email.subject;
current.incident_state = (1);
current.assignment_group.setDisplayValue("Alert mgmt");
current.impact = (2);
current.urgency = (1);
current.insert();
}
}
thanking you once again,
sry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2015 09:45 AM
I suspect at least part of your problem is with your syntax here : current.incident_state = (1);. The parens aren't correct here. I would look at the OOB 'Create Incident' rule. Is there any reason you can't use that with some small modifications? You can probably just make a copy of the OOB rule and make your specific changes.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-30-2015 12:27 PM
Hi Dan,
I think its working. For now i have tested with the below script and i didn't see any issues.
var emailFrom = email.from.toLowerCase();
var emailTo = email.to.toLowerCase();
var subject = email.subject;
var sid = gs.createUser(email.from);
if ( emailFrom.indexOf("abc@xyz.com") >= 0)
{
current.caller_id = sid;
current.description = email.body_text;
current.short_description = email.subject;
current.incident_state = (1);
current.assignment_group.setDisplayValue("Accounts");
current.category = "Account";
current.subcategory = "Incident ";
current.insert();
}
if (emailTo.indexOf("incsupport@xyz.com") >=0 ) {
var grInc = new GlideRecord('incident');
var grEmail = new GlideRecord('sys_email');
var incUpdated = false;
grEmail.addEncodedQuery('sys_created_on>=javascript:gs.minutesAgoStart(15)^subject=' + subject);
grEmail.query();
if(grEmail.getRowCount != 0){
while(grEmail.next() && incUpdated != true){
grInc.get(grEmail.instance);
if(grInc.active == true){
incUpdated = true;
event.state = "stop_processing";
}
}
}
if(incUpdated == false){
current.short_description = email.subject;
current.description = email.body_text;
current.caller_id = sid;
current.incident_state = 1;
current.assignment_group.setDisplayValue("INC support");
current.impact = (3);
current.urgency = (1);
current.insert();
}
}
thank you very much for your help,
sry