"Duplicate entry '<sys_id>' for key 'PRIMARY'" in workflow from script task

andersba
Giga Contributor

I am trying to create a request item that has, among other variables, a "related incident" reference. When this request item is submitted, if there's a related incident, I am opening that incident up and updating a "related record" field on it via a script task in the workflow. The flow is as such:

Start -> If (Has related incident is checked) -> Update incident -> (end if) -> Approval, tasks, etc.

This is my script task in the workflow:

if (current.variables.has_incident == "true") {
var gr = new GlideRecord('incident');
if (gr.get(current.variables.incident)) {
if (gr.u_parent_incident == '') {
gr.u_parent_incident = current.sys_id; // field name is u_parent_incident, but it's actually a reference to the task table... not my fault
}
gr.work_notes = "Peripheral hardware request " + current.number + " has been created for this incident.";
gr.update();
}
}

Everything appears to work fine; however, upon submission of the request, an error pops up:

Duplicate entry 'cdc391e84dbfcd4075480b189b3e5931' for key 'PRIMARY'

This guid is the sys_id of the new request item. Even with the error, everything functions properly - incident is updated, request workflow continues, the "show workflow" visualization has no errors, and so on. If I stick logging into the script, it will log current.sys_id and .number properly. I tried putting current.setNewGuid() at the beginning to attempt to force a sys_id generation, but that made it worse, so I took it back out.

Anybody know why this error is showing up?

4 REPLIES 4

bburdick
Mega Guru

Anyone have an idea of the cause and how to fix?


andersba
Giga Contributor

I think this error can be caused by many things. I opened a ticket in HI, and in my case, it was found to be an 'after' business rule that was occasionally updating an incident whenever that same incident was updated (this is bad), and my workflow just happened to trigger this case regularly. Your best bet is to open up a ticket with SN and they will help you debug it.


hookerdonte1
Giga Contributor

I had this error and it was the Business Rule "Set Process Stage -Approval". It did not have any conditions set for it. We disabled this business rule and it corrected our problem.

Regards,

Donte Hooker
Email: Donte@klovesinc.com
www.klovesinc.com


pclp
Kilo Explorer

I had the same error:

"Error Message Unique Key violation detected by database ((conn=271290) Duplicate entry '91a830a54983945085cdb14a691122fc' for key 'PRIMARY')"


In my case I used a business rule to assign the value to the field which didn't exist.
newTask.ms_doc = current.sys_id;