i am getting this Unique Key violation detected by database (Duplicate entry 'org.mozilla.javascript.Undefined' for key 'PRIMARY') when i tried to add a new attendee

keemac
Kilo Explorer

I followed the build a servicenow sample application and on Lab 15 i added a new business rule. I copied and pasted the javascript in the example and when i tried to add a new attendee i get the above message

4 REPLIES 4

Atul Kumar2
Giga Guru

Hi Kee,



Unique key violation comes when there is already record in the system with the same primary key. so attendee record will be already there in the system hence it is throwing an error.



Please check the attendee table and search for the name which you are creating now. it will be there so no need to create just you need to check if that attendee properties roles fulfills your requirement else you will have to create a attendee with different name.



Regards,


Atul Kumar


sergiu_panaite
ServiceNow Employee
ServiceNow Employee

The issue is usually caused by a business rule that runs before an insert and contains an current.update() operation. If that's the case, removing the current.update() fixes the issue. Check if you have any BRs of this type on that table.



Regards,


Hi, I am receiving the same error message when I am creating an RITM. The first time I trigger this script, it runs as desired. Subsequent times throws the error message. Debugging the script gives me unique sys_id's for both the RITM and the Request. Can you offer any help?



find_real_file.png


Along with making sure there are no current.update() calls in a before business rule or checking your tables Unique dictionary records, I have also found that an error like this will occur when you try to create a record via a script with a field name that does not exist on the table. Or, at least, trying to set the scope of a record that is not an application metadata record.



For instance, I'm copying a form and when I got down to the 'sys_ui_element' table, it turns out there is no sys_scope field on that table. Surprise!



Which meant my:
variable.sys_scope = scope.sys_id


line of code was causing the unique entry error. Since it simply didn't exist, I just took out that line of code and good to go.



It may not be an answer to your question, but I wanted to put this out there so it gives people with this error more to troubleshoot.