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.

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?








2 ACCEPTED SOLUTIONS

RaghavSh
Mega 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

Ron28
Mega Sage

Just found this post again and thought I'd update it with the cause for this issue. 

Thanks to Tom Hauri pointing me in this direction.
The issue is that the class name may get corrupted at times which causes it not to be shown whatever you do, but the record does exist. 
For my code, I added a list of columns to exclude from being copied, 'sys_class_name' is now one of them. I've not run into the same issue again.

Ron

View solution in original post

5 REPLIES 5

Ron28
Mega Sage

Just found this post again and thought I'd update it with the cause for this issue. 

Thanks to Tom Hauri pointing me in this direction.
The issue is that the class name may get corrupted at times which causes it not to be shown whatever you do, but the record does exist. 
For my code, I added a list of columns to exclude from being copied, 'sys_class_name' is now one of them. I've not run into the same issue again.

Ron