Unique Key Violation detected by Database error in service now.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-03-2022 04:31 AM
Hi guys,
I have a requirement to show, only HR cases, that belongs to the logged in user's assignment group.
I have create a before business query to achieve this
This is the main code.
This is working fine as per the requirement but a problem arises when a HR case got transferred.
When the logged in user transfers the case to some other HR service where his/her group is not in the assignment group, we get the following error " Unique Key Violation detected by Database error ". If I turned off the business rule there is no such error.
Can anyone kindly suggest me a better way to resolve this error and achieve the required business requirement.
Thanks in advance.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-03-2022 06:08 AM
Hi Dinesh,
Can you check if you have written an on before business rule on the incident which calls current.update() or any insert action?
Unique key violation usually occurs if you trying to update double update record.For ex, if you have current.update() in your before insert business rule. Check your scripts for this particular catalog item.
Mark my answer correct & Helpful, if Applicable.
Thanks,
Sandeep

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-03-2022 02:57 PM
"Unique Key Violation detected by Database error" occurs during an insert and not from query.
Make sure there is no other business rule or script that tries to insert a record to a table.
For example, following is a case of this error when users are using chat to create an incident.
https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0687017
Could it be there is another feature the uses the retrieved HR cases to create a new record?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-03-2022 03:08 PM
Almost forgot, it can also be an .update() on a record and not necessary just an insert().
Check if there's any business rule that'll update() or insert() a record.
To check, go to "System Definition" > "Business Rules". Filter on column "Table" to the table being use. Check if there is any business rule on the table.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-03-2022 10:12 PM
But that business rule seems to be the only issue. If i turned off that business all the transfer case scenarios are working fine.