Fix script get/update issue (RESOLVED)

mikeearnheart
Tera Contributor

Instance: Kingston  Patch 14

I am attempting to update a 'Receiving Slip Line Item' using a 'Fix Script'.

Script is as follows:

var rcli = new GlideRecord('proc_rec_slip_item');
rcli.get('RCL9999999');
rcli.query();
while (rcli.next())
	{
		gs.log('Receiving Slip Item: ' + rcli.sys_id,'me');
		gs.log('Serial Numbers: ' + rcli.u_serialnumbers, 'me');
		gs.log('Quantity: ' + rcli.quantity, 'me');
		rcli.u_serialnumbers = 'ACCC123456788|ACCC123456789';
		rcli.quantity = 2;
		rcli.update();
	}

Upon execution I get the following results:

[Domain Paths] Query against table proc_rec_slip_item restricted by domain values [ABC[<SYS_ID], global]
me: Receiving Slip Item: <SYS_ID>
me: Serial Numbers: ACCC123456788|ACCC123456789|ACCC1234567810
me: Quantity: 3
GlideSession message was modified by sanitization. [message=Unique Key violation detected by database (Duplicate entry &apos;<SYS_ID>&apos; for key &apos;PRIMARY&apos;)][sanitized=Unique Key violation detected by database (Duplicate entry &#39;<SYS_ID>&#39; for key &#39;PRIMARY&#39;)]
FAILED TRYING TO EXECUTE ON CONNECTION 4: INSERT INTO proc_rec_slip_item (`u_serialnumbers`, `quantity`, `purchase_line`, `sys_mod_count`, `u_isserialized`, `received`, `sys_updated_on`, `sys_domain_path`, `number`, `sys_id`, `received_by`, `sys_updated_by`, `receiving_slip`, `sys_created_on`, `sys_domain`, `sys_created_by`) VALUES('ACCC123456788|ACCC123456789', 2, '<SYS_ID>', 0, 1, '2019-04-24 15:13:15', '2019-04-25 20:54:01', '!!!/!!!/', 'RCL99999', '<SYS_ID>', '<SYS_ID>', '<EMAIL>', '<SYS_ID>', '2019-04-25 20:54:01', '<SYS_ID>', '<EMAIL>') /* abc021, gs:<SYS_ID>, <SYS_ID>*/
Unique Key violation detected by database (Duplicate entry '<SYS_ID>' for key 'PRIMARY')
: java.sql.SQLIntegrityConstraintViolationException: Duplicate entry '<SYS_ID>' for key 'PRIMARY': org.mariadb.jdbc.internal.SQLExceptionMapper.get(SQLExceptionMapper.java:132)

Based on the error statement it looks like its attempting to INSERT a duplicate record.

In the script I am executing an UPDATE.

WHY is it trying to execute an INSERT?

1 ACCEPTED SOLUTION

vkachineni
Mega Sage
Gr.get function takes in a sys_id and not a number. Try passing in sys_id.

View solution in original post

7 REPLIES 7

vkachineni
Mega Sage
Gr.get function takes in a sys_id and not a number. Try passing in sys_id.

get function can accept any column not only sys Id. If only one value is passed in then the system assumes it is the sys id. https://developer.servicenow.com/app.do#!/api_doc?v=kingston&id=r_GlideRecord-get_Object_Object

I was referring to the get() function in the code which was taking in a Number.

DScroggins
ServiceNow Employee
Hello, Please try the following: var rcli = new GlideRecord('proc_rec_slip_item'); rcli.addQuery('number','RCL9999999'); rcli.query(); while (rcli.next()) { gs.log('Receiving Slip Item: ' + rcli.sys_id,'me'); gs.log('Serial Numbers: ' + rcli.u_serialnumbers, 'me'); gs.log('Quantity: ' + rcli.quantity, 'me'); rcli.u_serialnumbers = 'ACCC123456788|ACCC123456789'; rcli.quantity = 2; rcli.update(); }