How to update a record in inbound email actions?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-04-2018 07:38 AM
We are creating an event system through email.
The email looks like this:
- Subject: <text>_SerialNumber_<text>
- Body: <Text that will trigger condition>
The inbound action will trigger on the body, and get the serial number from the subject. So far so good. Though we only want to have 1 incident open per CI with the given serial number. So if a new email comes in with a serial number, that has already an open incident, it should be updated. How should the inbound action look like?
First we tried:
var incident = new GlideRecord('incident');
incident.addQuery('cmdb_ci.serial_number', serial);
incident.addQuery('active', true);
incident.addQuery('contact_type', 'Automated Event');
incident.query();
if (incident.next()) {
incident.work_notes = email.body_text;
incident.update();
} else {
current.work_notes = email.body_text;
current.insert();
}
With this, it worked, though the attachments were not added, because we did not update the current object. So we tried:
var incident = new GlideRecord('incident');
incident.addQuery('cmdb_ci.serial_number', serial);
incident.addQuery('active', true);
incident.addQuery('contact_type', 'Automated Event');
incident.query();
if (incident.next()) {
current.get(incident.getUniqueValue());
current.work_notes = email.body_text;
current.update();
} else {
current.work_notes = email.body_text;
current.insert();
}
Now, the Target is set correctly and the attachments are transferred from the email to the incident, but the work notes are not added and we see the error:
java.sql.SQLIntegrityConstraintViolationException: Duplicate entry '5a4376cc376307401517ab2943990e29' for key 'PRIMARY':
So, how should I create an inbound action with type 'New', that updates a record and is able to transfer attachments?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-04-2018 09:36 AM
I'm thinking you need a separate query to get the CI, and use that in your addquery line for CI.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-05-2018 12:17 AM
No I don't. The querying is not the issue here. I get the correct incident just fine.