How can we move data from one table to another using fix script?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-11-2023 09:28 PM - edited 05-11-2023 10:32 PM
Hi All,
I want to move some records from one table to another table using the fix script.
Both tables are extending the same table.
I have drafted below script but it seems to be tedious work to map each and every column of both tables, Is there any way we can move these data without mapping when the table columns are same.
var gr = new GlideRecord("old_table");
gr.addEncodedQuery("query");
gr.query();
gr.autoSysFields(false);
gr.setWorkflow(false);
while(gr.next()) {
var newGr = new GlideRecord("new table");
newGR.field_name1 = gr.field_name1.toString();
newGR.field_name2 = gr.field_name2.toString();
//add the remaining fields one by one.
newGr.insert();
}