- 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
12-17-2018 06:04 AM
Hi all,
When subject line contains INC without any re:/RE: prefix-ServiceNow will update the INCIDENT mentioned inside the [INC000XXX] .
in the conditions i given like subject does not contains Re: .....but it creates a new incident..but actually my requirement is need to update the existing once. here i can change any condition or script? here i attached my screen shot and script?
how can i acheive this? its very urgent
Thanks in advance
chinna

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-03-2019 01:43 AM
Hello,
I used this and other posts to try and do this but, I think that because this post is so old, some of the information is out of date and so I thought I'd post my eventual solution in case anyone else comes here for the same thing:
Create a new Script Include called: passesEmailConditions
Client Callable: Yes
function passesEmailConditions(email){
var answer = true;
var gr = new GlideRecord('incident');
gr.addQuery('short_description', email.subject);
gr.addQuery('active', true);
gr.query();
if (gr.next())
{
gs.log(gr.number + ' is a duplicate issue of: ' + email.subject);
gs.log(gr.short_description);
gr.work_notes = 'Alert Triggered Again: ' + email.subject + email.body_text;
gr.update();
answer = false;
}
return answer;
}
This will check if there is an active incident with a short description that matches the subject line of the inbound email and then provide an answer which is either true or false.
If the answer is true, it will update the ticket it finds with the gr.work_notes text and add a log item (System Logs > System Log > All).
If the answer is false it will simply allow the inbound action to run.
In order to call this from the Inbound Action, find the inbound OOTB inbound action called "Create Incident" and open it. On the "When to run" tab, you'll see the condition box. Add
&& passesEmailConditions(email)
And save it.
To test, send an email to your instance with a unique subject line and one with a subject line of the short description from an existing active ticket and then look at the results.
The sit back and light a big ci-gar.
You might want to add some extra queries into the script include there. You can do with an encoded query or simply by adding more gr.query lines before the final gr.query();
Good luck.