Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Getting Unique Key Constraint

mohantym
Tera Contributor

Hi All,

 

I am trying a basic program on my local dev instance (Tokyo release) to update an existing Incident and getting below error. Can someone please check and let me know what is wrong here ? 

 

Many Thanks in advance.


var incidentGR = new GlideRecord('incident');
incidentGR.get('INC0010003');
gs.log(incidentGR.number);
incidentGR.urgency = 2;
gs.log(incidentGR.urgency);

incidentGR.update();

 

 

FAILED TRYING TO EXECUTE ON CONNECTION glide.3 (connpid=3637): INSERT INTO task (`made_sla`,`upon_reject`,`sys_updated_on`,`a_int_6`,`task_effective_number`,`a_int_1`,`sys_class_name`,`number`,`sys_id`,`sys_updated_by`,`a_int_2`,`opened_by`,`urgency`,`sys_created_on`,`sys_domain`,`state`,`reassignment_count`,`sys_created_by`,`knowledge`,`a_int_3`,`approval`,`impact`,`sys_mod_count`,`active`,`a_int_7`,`priority`,`sys_domain_path`,`opened_at`,`escalation`,`upon_approval`,`a_str_1`) VALUES(1,'cancel','2022-12-23 08:27:43',0,'INC0010003',1,'incident','INC0010003','02d2727b2f335110349aa55df699b690','admin',1,'6816f79cc0a8016401c5a33be04be441',2,'2022-12-23 08:27:43','global',1,0,'admin',0,3,'not requested',3,0,1,0,4,'/','2022-12-23 06:28:16',0,'proceed','inquiry') /* dev98047001, gs:5323F6F72FF35110349AA55DF699B6A0, tx:eb2ec3f72f375110349aa55df699b6fe */ 
Unique Key violation detected by database ((conn=3637) Duplicate entry '02d2727b2f335110349aa55df699b690' for key 'PRIMARY')
: java.sql.SQLIntegrityConstraintViolationException: (conn=3637) Duplicate entry '02d2727b2f335110349aa55df699b690' for key 'PRIMARY': 	org.mariadb.jdbc.internal.util.exceptions.ExceptionMapper.get(ExceptionMapper.java:229)
	org.mariadb.jdbc.internal.util.exceptions.ExceptionMapper.getException(ExceptionMapper.java:165)
	org.mariadb.jdbc.MariaDbStatement.executeExceptionEpilogue(MariaDbStatement.java:238)

 

1 ACCEPTED SOLUTION

Veer
Tera Guru

@mohantym  Please retrieve the record by passing sys_id to the get() function, or write something like this.

var incidentGR = new GlideRecord('incident');
incidentGR.get('number','INC0010003');
gs.log(incidentGR.number);
incidentGR.urgency = 2;
gs.log(incidentGR.urgency);

incidentGR.update();

OR

 

var incidentGR = new GlideRecord('incident');
incidentGR.get('sysIdofthe incident record');
gs.log(incidentGR.number);
incidentGR.urgency = 2;
gs.log(incidentGR.urgency);

incidentGR.update();

View solution in original post

1 REPLY 1

Veer
Tera Guru

@mohantym  Please retrieve the record by passing sys_id to the get() function, or write something like this.

var incidentGR = new GlideRecord('incident');
incidentGR.get('number','INC0010003');
gs.log(incidentGR.number);
incidentGR.urgency = 2;
gs.log(incidentGR.urgency);

incidentGR.update();

OR

 

var incidentGR = new GlideRecord('incident');
incidentGR.get('sysIdofthe incident record');
gs.log(incidentGR.number);
incidentGR.urgency = 2;
gs.log(incidentGR.urgency);

incidentGR.update();