How to copy a record from one table to another table

Carol543
Mega Contributor

I want to copy all the records in table A to table B.
Is there a way to copy in a script without using record export / import?

1 ACCEPTED SOLUTION

Gunjan Kiratkar
Kilo Patron
Kilo Patron

Hi @Carol543 ,

You can write a background script

 

var gr = new GlideRecord('tableA');
gr.query();

gr.setLimit(1); // test for 1 record after that use 100 or 500 as limit so that browser will not hang
while (gr.next()){
var rec = new GlideRecord("tableB");

rec.initialize();

rec.field = gr.field; // map the field name like this

rec.insert(); // insert to b table
}

 

Regards,

Gunjan Kiratkar 


Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy

View solution in original post

8 REPLIES 8

Carol543
Mega Contributor

As of now It is one time use only and may be needed to use in future as well as per requirement.

I would just create in flow designer similar to this structure. No code required, just drag and drop.

Mike_R_0-1667502583587.png

 

Hi,

How to use fix scripts to move data from parent tables to child tables?

Eg: from server table to windows and linux tables?

Thanks

rakeshtalla13
Tera Contributor

But in this case, do we have to add all fields at "Create Record" Field values