How do I prevent a Unique Key Violation when creating a Taskfrom a workflow?

Tim Wmson
Giga Expert

I have an approval workflow that executes correctly until I add a Create Task item at the end. It creates a ticket in the Incident table but generates the following error:

Unique Key violation detected by database (Duplicate entry 'b9eec7c40fce4a40b2908b2022050eb5' for key 'PRIMARY')

When I remove the Create Task from the workflow it doesn't throw the unique key violation. The Create Task item in the workflow is using a template to create the Incident.

1 ACCEPTED SOLUTION

Tim Wmson
Giga Expert

I opened an Incident with HI and got a good answer. A business rule was causing the aforementioned error. The Check for Children Resolved BR was the culprit. Disabling that BR stopped the unique key error.


View solution in original post

8 REPLIES 8

Yes, with no error


ggiri1
ServiceNow Employee
ServiceNow Employee

Hi Tim,



On which table you are creating the record using create task activity? If you are creating it on table "incident", you need to look for the BRs on incident table also. You might be updating the same record twice in BRs.



Also make sure you do not have any current.update() OR current.insert() in BRs or in the catalog task activity in workflow.


coryseering
ServiceNow Employee
ServiceNow Employee

Hi Tim,



Did you figure this one out yet?



Issues like these can be hard to track down. The error will be either very easy (dual-calls to insert() on GlideRecord within the code path), really tricky and hard to find (The call is buried 4 layers deep behind 3 Script Includes and only happens when a specific event is processed), or a platform-level bug (impossible to determine without reproducing, looking at all the source available and sometimes enabling hardcore debugging techniques).



If you don't have it solved via the suggestions here, I recommend opening an Incident in Hi so Support can start tracking down the issue.


Tim Wmson
Giga Expert

I opened an Incident with HI and got a good answer. A business rule was causing the aforementioned error. The Check for Children Resolved BR was the culprit. Disabling that BR stopped the unique key error.