The CreatorCon Call for Content is officially open! Get started here.

Unique Key violation detected by database ((conn=999850) Duplicate entry '781b08101b739450c91421b4bd4bcb90' for key 'PRIMARY')

Arnold Zwane2
Mega Contributor

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.  

15 REPLIES 15

Hi Asifnoor,

I tried with this code and got the same error message.

Kind Regards

Arnold

Okay decativate this BR.

Go to incidents and check the count.

And then test it

Then go to incidents and check the count again and see if any incident got created.

Hi Jack,

The Business Rule is a Before Insert or Update.  

You may be up to something with the loop idea. I just can't figure out where the loop would come from when looking at my script. Can you please check and see if you might pick up something that I couldn't? I will past it underneath.

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 = 3;
current.close_notes = 'Transferred to Incident';


//English or Null
if ((current.u_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 <a href="/incident.do?sys_id='+inc.sys_id+'">'+inc.number+'</a> created.');

//Brazilian Portuguese
if (current.u_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 <a href="/incident.do?sys_id='+inc.sys_id+'">'+inc.number+'</a> criado.');

//Spanish
if (current.u_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 <a href="/incident.do?sys_id='+inc.sys_id+'">'+inc.number+'</a> 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

Arnold

You need to remove update.

Becuase you are creating incident again in the BR. Do you want incident to be created on new call insert as well as update? If not then uncheck update from your BR.

Hi Arnold,

Based on your script, I think you can try to append a condition active = true on BR.

Hope this will help!