Inbound action creating duplicate incident
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-27-2020 07:31 AM
Hi!
I created an inbound action to create and then update incidents with the same email subject by querying the short description. The action is updating the incidents but at the same time also creating a new incident with the same subject. I checked the logs and it seems like the action is first triggered with "update", and the incident is created.
Then when another email is recieved with the same subject, the action is triggered once, but creating a new as well as updating the incident. No other inbound actions are triggered for these emails. Could the issue be business rules on the incident table or do I maybe need something else to prevent the duplicate creation?
I'm setting the fields like assignment group, short description and description with Field Actions
Here is the code:
(function runAction(/*GlideRecord*/ current, /*GlideRecord*/ event, /*EmailWrapper*/ email, /*ScopedEmailLogger*/ logger, /*EmailClassifier*/ classifier) {
var emailSubject = email.subject;
var gl = new GlideRecord('incident');
gl.addQuery("short_description", emailSubject);
gl.addEncodedQuery("sys_created_onONToday@javascript:gs.beginningOfToday()@javascript:gs.endOfToday()^active=true");
gl.query();
if(gl.next()){
gl.work_notes = "Incident updated from the same alert";
gl.update();
}
})(current, event, email, logger, classifier);
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-27-2020 07:47 AM
hello if you are just creating one incident.
you can use current.insert() .
By looking at your filter i think you are updating an incident so
you should have look at Update incident inbound action to get idea of it to how to code and don't forget to select type as Reply for update.
it is something like below.
gs.include('validators');
if (current.getTableName() == "incident" && current.short_description == emailSubject) {
current.comments = "Incident updated from the same alert";
current.update();
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-27-2020 08:04 AM
Hi,
Since it does not have watermark & is a not a Reply mail it will create an incident as the conditions are met & is expected. In your case you can create a business rule on incident table that runs before insert & checks the short description. Tf there exists you need to abort the action.