- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā04-25-2019 04:09 PM
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 '<SYS_ID>' for key 'PRIMARY')][sanitized=Unique Key violation detected by database (Duplicate entry '<SYS_ID>' for key 'PRIMARY')]
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?
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā04-25-2019 04:17 PM
Vinod Kumar Kachineni
Community Rising Star 2022

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā04-25-2019 04:34 PM
Also FYI when you use gr.get() you must pass in the sys_id of the record you are trying to receive. You can also specify a different unique field as in your case RCL9999999 but when you use anything besides sys_id you must specify the field to search as the first parameter like so gr.get('number', 'RCL9999999').
When you use gr.get() there also is no query() or next() methods as the system will retrieve the record specified. You just call gr.get() and assuming the record exists then you will have immediate access to the returned record object. Now to answer why you are seeing 'INSERT' errors. When you use the gr.get() function if the system does not find the record it will create one using the passed in single parameter as the new record sys_id. It's best practice to wrap gr.get() functions in IF statements like so:
if(gr.get(SYS ID)){
//Do something with gr
}
This way new records will not be created if not found using gr.get().
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā04-25-2019 05:17 PM
Try this out...
var rcli = new GlideRecord('proc_rec_slip_item');
if(rcli.get('RCL9999999')){
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();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā04-26-2019 07:35 AM
I can confirm that both options worked.
gr.get(<sys_id>)
and
gr.get('number','RCL99999')
will update as expected.
Thanks,
for your help!