Unique Key violation message when updating request short description

ccorscadden
Kilo Contributor

I'm trying to update the short description on my request with the requested item's catalog item display value with an on after business rule. The script works and the short description is updated but I keep getting a message like Unique key violation detected by database (duplicate entry '81135af74f57124029de98701310c7a0' for key primary). I'm not sure why this message is appearing and what is relates to.

My business code like like the following

var request = new GlideRecord("sc_request");

var item = new GlideRecord("sc_cat_item");

request.get(current.request);

item.get(current.cat_item);

request.short_description = item.getDisplayValue();

request.update();


1 ACCEPTED SOLUTION

sergiu_panaite
ServiceNow Employee
ServiceNow Employee

Hi Chris,



The error you are getting is a database error and it means that you are trying to do an insert for a sys_id that already exists. This usually happens if you have a before BR with current.update() which would trigger an insert already.



Regards,


View solution in original post

8 REPLIES 8

Mihir Mohanta
Kilo Sage

There may be some other business rule written in sc_request table which is causing this error.



The sys_id in the error message is same every time or different?



This sys_id belongs to which tables record ?



Thanks,


Mihir


hello, I would be interested in your opinion in case the sys_id displayed in the error log is always different. Thank you in advance.

rajmasurkar
Giga Guru

Hi Chris,



Unique key means the error is related with sys_id.


I would advice you to change request.get(current.request) to request.get( current.sys_id).





Raj


Abhinandan Pati
Giga Guru

Hi Chris,



Make sure that there is no 'current.update();' statement in any of your 'Before' business rules.



Thanks


Abhinandan