Copying records from one table to another

MrBun256
Tera Contributor

I created a Custom Table by using ‘Extends table’, which references another table. Basically, I copied everything from that table and will later add Dictionary Entries to reference data from other tables for this Custom Table.


When using the REST API Explorer to test out the response, nothing returns. I realized that extending the table does not automatically copy records from the parent table. How would I go about this to copy the dynamic records from the parent table? Perhaps a Business Rule?

_______________________________________________________

EDIT: 

Thank you for the responses. I want to have all records from (table A) copied to (table B). I also want to copy all records from another table (table C) to (table B) as well. The records in both (table A) and (table C) are dynamic, they are updated queues. Basically, I am combining all data records from (table A) and (table C) to make (table B). I do not want to mess with the data in (table A) or (table C) in any way. This is not a one time migration since the data queues are always updating in (table A) and (table C).

1 ACCEPTED SOLUTION

Mwatkins
ServiceNow Employee
ServiceNow Employee

A third idea occurred to me based on the Out-of-box "Insert and Stay" UI Action. If you call the "insert()" method on a GlideRecord that already exists it will create a copy - no need to manually set all the field values. So, in a Business Rule that runs after/insert on table A, with an explicit condition for "Class" is "Table A", you could do this:

current.setValue("sys_class_name", "table_b");
current.insert();

Provided the tables are in the same hierarchy, this should just copy all the fields right over. In fact, I think this will work for tables that aren't even in the same hierarchy as long as the field names are exactly the same.

Please Correct if this solves your issue and/or  👍 if Helpful

View solution in original post

9 REPLIES 9

sachin_namjoshi
Kilo Patron
Kilo Patron

if you want to do this one time, then there are many ways like below

 

- Export XML from core table to your extended custom table using Import XML feature.( if you don't have many number of records)

 

https://docs.servicenow.com/bundle/orlando-platform-administration/page/administer/development-best-practices/concept/c_ExportAndImportXMLFiles.html

 

- If you have too many records to copy, then you can configure fix script to copy data between tables.

 

- If you want to do this ongoing, then you can configure flow designer with flows to copy records.

 

https://docs.servicenow.com/bundle/orlando-servicenow-platform/page/administer/flow-designer/reference/create-record-flow-designer.html

 

Regards,

Sachin

 

 

Hi Sachin,

 

Using fix scripts, how to move datas from parent class to child classes?

Eg: from server table to windows and Linux table.

 

Mwatkins
ServiceNow Employee
ServiceNow Employee

The idea of extending tables in ServiceNow is so that the behavior and fields of the parent table gets inherited by its children, allowing you to avoid rewriting the same code over and over. However, the data in the parent table (all the records) do not exist in the child tables. On the other hand, records in the child tables do automatically exist in the parent table.

It sounds like you want to have all records in the parent table (table A) automatically get copied into the child (table B). In that case, why not just create the records directly table B? Since data in child tables also exists in all the parent tables (one record that exists in both A and B tables)

I'm not sure I can answer this question because I don't understand why you want to do this. Are you attempting to change the table to which these records belong or copy them (i.e. end up with two records, one in A and one in B)?

Also, is this a one time migration or a dynamic thing that would always happen?

Thank you for responding. I want to have all records from (table A) copied to (table B). I also want to copy all records from another table (table C) to (table B) as well. The records in both (table A) and (table C) are dynamic, they are updated queues. Basically, I am combining all data records from (table A) and (table C) to make (table B). I do not want to mess with the data in (table A) or (table C) in any way. This is not a one time migration since the data queues are always updating in (table A) and (table C).