The CreatorCon Call for Content is officially open! Get started here.

GlideRecord Update/Insert puzzle.

Ron28
Mega Sage

I'm a bit stumped by this. I have a tool to copy records from the PRD instance to the QA instance.  

The code is getting records via the table API into QA, then I set the sys_id from the PRD instance using 

setNewGuidValue() then check if the record exists, if so update it and if not, insert it.

The issue I have is that a gr.get(sys_id) returns no record. I would have thought that meant the record doesn't exist, so the code does the gr.insert() which returns a null value.

I ran the code in a background script which shows the following error:

Unique Key violation detected by database (ERROR: duplicate key value violates unique constraint "cmdb_pkey"
So the sys_id appears to be used.

The table I am copying is a custom table which is extended from 'hardware', which in turn is extended from 'configuration item'.  I checked via url:

<instance>.service-now.com/u_cmdb_ci_biopod.do?sys_id=01273a9b1b37c61092ad99798b4bcbc2
says record not found

<instance>.service-now.com/cmdb_ci_hardware?sys_id=01273a9b1b37c61092ad99798b4bcbc2
returns record not found, but the url changes to show table u_cmdb_ci_biopod with the same sys_id

<instance>.service-now.com/cmdb_ci.do?sys_id=01273a9b1b37c61092ad99798b4bcbc2
returns record not found, but the url changes to show table u_cmdb_ci_biopod with the same sys_id

My question is, why can I not find the record with that sys_id, which clearly is in the custom table as the table update or insert fails. But I can't see it or do a GlideRecord get() on it.  Is there a record that keeps track of sys_ids for each table that still has the sys_id value as being used yet there is no table item using it?








1 ACCEPTED SOLUTION

RaghavSh
Kilo Patron

Do you have Sn utils? check if the sys_id (01273a9b1b37c61092ad99798b4bcbc2) is used of some other record. 

 

Refer : https://www.servicenow.com/community/in-other-news/global-sys-id-search/ba-p/2430592 

 

You are trying to setup the sys_id of a record, which is from prod. I believe it is going to fail somewhere or other.

The chances of having same sys_ids across instances are less but it can still exist. I would 


Please mark the answer correct/helpful accordingly.


Raghav
MVP 2023
LinkedIn

View solution in original post

3 REPLIES 3

RaghavSh
Kilo Patron

Do you have Sn utils? check if the sys_id (01273a9b1b37c61092ad99798b4bcbc2) is used of some other record. 

 

Refer : https://www.servicenow.com/community/in-other-news/global-sys-id-search/ba-p/2430592 

 

You are trying to setup the sys_id of a record, which is from prod. I believe it is going to fail somewhere or other.

The chances of having same sys_ids across instances are less but it can still exist. I would 


Please mark the answer correct/helpful accordingly.


Raghav
MVP 2023
LinkedIn

Ankur Bawiskar
Tera Patron
Tera Patron

@Ron28 

what's the business use-case for this copy?

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Ron28
Mega Sage

Thanks for the link to SN Utils.
The use case is to set up a new instance with cmdb data. Keeping the sys_id from PRD has some advantages to keep references working.

Thank you.
Ron