How to create an exception like this java.sql.BatchUpdateException: Duplicate entry?

sifynm
Tera Expert

                  I am trying to recreate an exception like this java.sql.BatchUpdateException: Duplicate entry '0046b3f6bb927240f3611272dbdb75b8' for key 'PRIMARY' -   I happened to find the solution for the same mentioned here: https://community.servicenow.com/thread/230668, but I would like to know what made this exception and I need to do to get an error message likewise.

1 ACCEPTED SOLUTION

sergiu_panaite
ServiceNow Employee
ServiceNow Employee

In the exception you posted, the duplicate key is 'PRIMARY' which is a unique index on sys_id column (as this column is marked as PRIMARY KEY).



To reproduce this:


- have a before insert business where you use current.update()



that's the easiest way to reproduce probably.


View solution in original post

5 REPLIES 5

Raju Koyagura
Tera Guru

For an example in sys_user table one user_name (yvette.kokoska) is already existing but still you are trying to insert one more user record with the same user_name, you will get the error.


You can try this in background script also..


var gr=new GlideRecord("sys_user");


gr.initilize();


gr.user_name="yvette.kokoska"; //replace with already existing user_name


gr.insert();


gs.info("Value is: "+gr.name);