- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-12-2014 02:02 PM
So this is a scenario, I am trying to create an Inbound Email action for the Windows Server team and they would like for it to create an automated Incident. These are outages and sometimes will have two or three outages email being sent out a night.
I created an Inbound Email that takes a simple condition and creates a Incident on the very first email alert. However, when the same email sends it a second time around, it is creating a new Incident. I would like it to update the current Incident instead of creating a new one. I have tried playing with the "Type" and set it to "Reply" (which does not make sense) on the Inbound Email. I want to know if this is even possible?
I have a Inbound Email that takes email.from.indexOf('TSMSAT01@Brunswick.com') >= 0 for a condition. I would really appreciate if anyone has any idea.
Solved! Go to Solution.
- Labels:
-
Incident Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2014 03:59 PM
Yes this is possible. Is the sender's email address unique enough to isolate your alerts? In my example, I'll use the email subject to search for previous email alert within the same day. If there is an active incident, any additional email will be added as a work note to the first email. If the incident is not active, a new incident is created.
Type is New Inbound Email action.
//Check for Current Open Incident and Update
var eSubject = email.subject;
var grInc = new GlideRecord('incident');
var grEmail = new GlideRecord('sys_email');
var incUpdated = false;
grEmail.addEncodedQuery('sys_created_onONToday@javascript:gs.daysAgoStart(0)@javascript:gs.daysAgoEnd(0)^subject=' + eSubject);
grEmail.query();
if(grEmail.getRowCount != 0){
while(grEmail.next() && incUpdated != true){
grInc.get(grEmail.instance);
if(grInc.active == true){
incUpdated = true;
grInc.work_notes = '\nFrom: ' + email.from + '\nTo: ' + email.to + '\nSubject: ' + email.subject + '\n\n' + email.body_text;
grInc.update();
}
}
}
if(incUpdated == false){
//Creates a new Incident ...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2014 06:18 AM
Shoaib,
The inbound email script goes before the if(incUpdated == false){ current.insert(); }
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2014 07:43 AM
Thank you
Shoaib
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2014 08:01 AM
Hello, I have a similar use case - I have automated emails coming in with incident notifications and a new servicenow incident is created for each email. I would like emails with the same subject to be added to the first incident.
I tried using the above code by creating a new inbound email action, but when I activate it all email updates stop. Can anyone give the proper context for using this code? Should I add that code to an existing inbound action instead?
Thanks,
Adam
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2014 08:10 AM
Adam,
This is how we have used it and works for us. Below is full inbound action that checks for open incidents and updates an incident if it matches the condition and is not in resolved or closed state.
If no open incidents found for then a new incident is created.
//Check for Current Open Incident and Update
var eSubject = email.subject;
var grInc = new GlideRecord('incident');
var grEmail = new GlideRecord('sys_email');
var incUpdated = false;
grEmail.addEncodedQuery('sys_created_onONToday@javascript:gs.daysAgoStart(0)@javascript:gs.daysAgoEnd(0)^subject=' + eSubject);
grEmail.query();
if(grEmail.getRowCount != 0){
while(grEmail.next() && incUpdated != true){
grInc.get(grEmail.instance);
if(grInc.active == true && grInc.state < 6){ //is the existing incident active and not in closed or resolved state
incUpdated = true;
grInc.work_notes = '\nFrom: ' + email.from + '\nTo: ' + email.to + '\nSubject: ' + email.subject + '\n\n' + email.body_text;
grInc.update();
}
}
}
if(incUpdated == false){ // If existing incident not found create new
current.comments = "received from: " + email.origemail + "\n\n" + email.body_text;
current.short_description = email.subject;
current.description = email.body_text;
var sid = gs.createUser(email.from);
current.caller_id = sid;
current.u_category = "Help/Assistance";
current.u_subcategory = "Network";
current.u_subcategory_2 = "Access Control";
current.state = 2;
current.contact_type = "email";
current.assignment_group.setDisplayValue("Grp_Snow_Service Desk");
current.u_owner.setDisplayValue("Grp_SNow_Service Desk");
current.impact = 3;
current.urgency = 1;
current.insert();
}
I hope this helps.
Shoaib
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-21-2014 03:13 AM
Hi Jordon/Tou,
The method mentioned by Jordon works correctly, by if you check the logs, the Target field for the incoming email is not setup. Is there a way we can update the Logs so that it reflects the correct target for an email
Thanks and regards,
Pratik Limbore