- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-14-2020 11:50 PM
hi,
i have an inbound action to create incidents from email.
The requirement is that i want to ignore incident creation if subject is same and add that mail content in existing incident itself.
Please let me know if any idea on this.
ServiceNow Community Rising Star 2022/2023
Solved! Go to Solution.
- Labels:
-
Integrations
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-15-2020 12:00 AM
Hi jagjeet,
Assuming subject is stored in short description of incident.
in your inbound action, check like this. This way, if short description exists already for any incident, then it will update the same incident. otherwise, it will create any new incident.
var gr = new GlideRecord("incident");
gr.addQuery("short_description",email.subject.toString());
gr.query();
if(gr.next()) {
gr.work_notes=email.body_text;
gr.update();
}else {
current.short_description = email.subject;
current.description=email.body_text;
//add other fields here.
}
Kindly mark the comment as a correct answer and helpful if it helps to solve your problem.
Regards,
Asif
2020 ServiceNow Community MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-15-2020 01:01 AM
This worked. Many thanks!
i just had to add current.insert() function in else condition.
ServiceNow Community Rising Star 2022/2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-17-2024 04:09 AM
Dear Community,
I have similar requirement to update the existing incident if existing incident number is mentioned in subject of email. in my script existing incident is updating , however along with existing incident update, it is creating an incident too. Can someone help to just update the existing incident not to create new incident

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-15-2020 12:00 AM
Hi Jagjeet,
You can try using below filter in your Inbound action
Thanks,
Jaspal Singh

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-15-2020 01:44 AM
Hi Jagjeet,
I see that you already got the correct answer for your question however I would like to add few things which came up in my mind please find below the same:
1. What if the email is received with same short description and description but with different user?
2. What if the email is received with the same user but the previous incident is old and inactive?
Unfortunately for the above two scenarios the script which asifnoor provided will fail. So I added few more validations which will overcome the above two scenarios please find the updated script below:
(function runAction(/*GlideRecord*/ current, /*GlideRecord*/ event, /*EmailWrapper*/ email, /*ScopedEmailLogger*/ logger, /*EmailClassifier*/ classifier) {
var gr = new GlideRecord("incident");
gr.addActiveQuery(); //search only for the active incidents
gr.addQuery("short_description",email.subject.toString());//search for same short description
gr.addQuery("description",email.body_text.toString()); //search for the same description
gr.addQuery("caller_id",gs.getUserID()); //search for the incident of same caller
gr.query();
if(gr.next()) {
gr.work_notes=email.body_text;
gr.update();
}
else {
current.short_description = email.subject;
current.description=email.body_text;
current.caller_id=gs.getUserID();
current.contact_type = "email";
//add other fields here.
current.insert();
}
})(current, event, email, logger, classifier);
Regards,
Alok
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-15-2020 02:23 AM
very valid points Alok. Thanks for sharing. I've modified my script.
ServiceNow Community Rising Star 2022/2023