Duplicate records on insert or update
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-30-2017 07:16 AM
Hello,
I am using a run script to update or insert a new record. However, I observed that my script is creating multiple records. Sometimes, it creates like 40 or so records with only 1 being the correct record that. My code is below.
///
var grp = new GlideRecord('proc_po');
grp.addQuery('number',current.sys_id); //Check if number & sys_id exists
if(grp.next()){ //check if records exists
grp.setValue('vendor', current.variables.u_vendor); //vendor
grp.vendor_account = current.variables.u_vendor_account; //
grp.update();
}else {
grp.initialize();
grp.short_description = current.cat_item.name;
grp.setValue('vendor', current.variables.u_vendor); //vendor
grp.setValue('product_catalog', current.cat_item.name); //set Item Requested
grp.setValue('ship_to', current.variables.u_ship_to);
grp.setValue('requested_by', current.request.requested_for); //set Requested by
grp.insert();
///

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-30-2017 07:26 AM
Hi Zack,
Code seems to be fine you can try using something as below
///
var grp = new GlideRecord('proc_po');
grp.addQuery('number',current.sys_id); //Check if number & sys_id exists
if(grp.next())
{ //check if records exists
gs.log('In loop for group update');
grp.setValue('vendor', current.variables.u_vendor); //vendor
grp.vendor_account = current.variables.u_vendor_account; //
grp.update();
}
else
{
gs.log('In loop for creationi of grup');
var grp1 = new GlideRecord('proc_po');
grp1.initialize();
grp1.short_description = current.cat_item.name;
grp1.setValue('vendor', current.variables.u_vendor); //vendor
grp1.setValue('product_catalog', current.cat_item.name); //set Item Requested
grp1.setValue('ship_to', current.variables.u_ship_to);
grp1.setValue('requested_by', current.request.requested_for); //set Requested by
grp.insert();
}
///
Have added appropriate logs for update kindly use that to check & get better understanding.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-31-2017 07:48 AM
Thanks a lot Jaspal,
It didn't quite work as I expected. I still have multiple records created.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-31-2017 08:15 AM
Did you get any chance to monitor the logs.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-02-2017 07:15 AM
Thanks Jaspal.
Yes, the log shows the same number of instance of record creation.