Unique Key violation detected by database ((conn=999850) Duplicate entry '781b08101b739450c91421b4bd4bcb90' for key 'PRIMARY')
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-07-2020 05:45 AM
We have a Business Rule that creates an Incident from a New Call. When it runs, it gives the following error message, but continue to create the incident as expected:
"Unique Key violation detected by database ((conn=999850) Duplicate entry '781b08101b739450c91421b4bd4bcb90' for key 'PRIMARY')"
I found many pointers from this Community advising against the use of "current.update()" on Business Rules. I then commented this part out of my script, but I still get the same error.
Could you please advise what else could be causing this error.
Background info: This Buiness Rule was converted from a UI Action where everything was working fine, but the same script gives the error on a Business Rule.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-07-2020 05:51 AM
Hi,
When creating incident, can you check which values are you inserting.
And can you share the code of the Br. Did you use initialize() before inserting a new record?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-07-2020 05:59 AM
Hi Asifnoor,
I didn't you use initialize() before inserting a new record - my code below:
var inc = new GlideRecord("incident");
inc.parent = current.sys_id;
inc.caller_id = current.u_requested_for;
inc.assignment_group = current.assignment_group;
inc.impact = 4;
inc.urgency = 4;
inc.contact_type = current.contact_type;
inc.opened_by = gs.getUserID();
inc.location = current.location;
inc.short_description = current.short_description;
inc.description = current.description;
var sysID = inc.insert();
//Set the New Call Record
current.parent = sysID;
current.active = false;
current.state = 1;
current.close_notes = 'Transferred to Incident';
current.u_call_type = 'Incident';
//English or Null
if ((current.requested_for.preferred_language == 'en') || (current.requested_for.language == ''))
current.comments = "An incident was logged with INCIDENT NO: " + inc.number;
if ((inc.opened_by.preferred_language == 'en') || (inc.opened_by.preferred_language == ''))
gs.addInfoMessage("Incident " + inc.number + " created");
//Brazilian Portuguese
if (current.requested_for.preferred_language == 'pb')
current.comments = "O Incidente foi criado com o número: " + inc.number;
if (inc.opened_by.preferred_language == 'pb')
gs.addInfoMessage("Incidente " + inc.number + " criado");
//Spanish
if (current.requested_for.preferred_language == 'es')
current.comments = "Un incidente ha sido logueado con Nro de Incidente: " + inc.number;
if (inc.opened_by.preferred_language == 'es')
gs.addInfoMessage("Incidente " + inc.number + " creado");
GlideSysAttachment.copy('new_call', current.sys_id, 'incident', sysID);
//var mySysID = current.update();
gs.setRedirectURL(inc); // Redirect to an incident record
gs.setReturnURL(current); //return to the New Call record
Kind Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-07-2020 06:04 AM
Also my Redirect doesn't work even thought I added the code as follow:
gs.setRedirectURL(inc);
where inc is the created incident.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-07-2020 06:29 AM
Try like this.
var inc = new GlideRecord("incident");
inc.initialize();
inc.parent = current.sys_id;
inc.caller_id = current.u_requested_for;
inc.assignment_group = current.assignment_group;
inc.impact = 4;
inc.urgency = 4;
inc.contact_type = current.contact_type;
inc.opened_by = gs.getUserID();
inc.location = current.location;
inc.short_description = current.short_description;
inc.description = current.description;
var sysID = inc.insert();
inc.get(sysID);
//Set the New Call Record
current.parent = sysID;
current.active = false;
current.state = 1;
current.close_notes = 'Transferred to Incident';
current.u_call_type = 'Incident';
//English or Null
if ((current.requested_for.preferred_language == 'en') || (current.requested_for.language == ''))
current.comments = "An incident was logged with INCIDENT NO: " + inc.number;
if ((inc.opened_by.preferred_language == 'en') || (inc.opened_by.preferred_language == ''))
gs.addInfoMessage("Incident " + inc.number + " created");
//Brazilian Portuguese
if (current.requested_for.preferred_language == 'pb')
current.comments = "O Incidente foi criado com o número: " + inc.number;
if (inc.opened_by.preferred_language == 'pb')
gs.addInfoMessage("Incidente " + inc.number + " criado");
//Spanish
if (current.requested_for.preferred_language == 'es')
current.comments = "Un incidente ha sido logueado con Nro de Incidente: " + inc.number;
if (inc.opened_by.preferred_language == 'es')
gs.addInfoMessage("Incidente " + inc.number + " creado");
GlideSysAttachment.copy('new_call', current.sys_id, 'incident', sysID);
//var mySysID = current.update();
gs.setRedirectURL(inc); // Redirect to an incident record
gs.setReturnURL(current); //return to the New Call record