- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-14-2022 01:26 AM
Hi community,
we are trying to copy the data from Assessment instance table to a custom table we created with similar fields,
initially we want to copy all the data from Assessment table and after that we want to create a scheduled job that runs daily and copies all the assessments that are created that day, please help me with the script that will let us copy all the data to the custom table.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-14-2022 01:33 AM
Hi,
try below code
Note : replace incident table with assessment table and u_custom with your custom table name.
var gr = new GlideRecord('incident');
gr.query('active",'true');
if(gr.next()){
var gr1 = new GlideRecord('u_custom');
gr1.initialize();
gr1.u_name= gr.name;
gr1.u_number = gr.number;
gr1.insert();
}
Or create business rule on assessment table and try below code
var gr1 = new GlideRecord('u_custom');
gr1.initialize();
gr1.u_name= current.name; // replacefield name as per your requirement
gr1.u_number = current.number;
gr1.insert();
}
.
Please mark my response as correct answer or helpful if applicable
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-14-2022 01:33 AM
Hi,
try below code
Note : replace incident table with assessment table and u_custom with your custom table name.
var gr = new GlideRecord('incident');
gr.query('active",'true');
if(gr.next()){
var gr1 = new GlideRecord('u_custom');
gr1.initialize();
gr1.u_name= gr.name;
gr1.u_number = gr.number;
gr1.insert();
}
Or create business rule on assessment table and try below code
var gr1 = new GlideRecord('u_custom');
gr1.initialize();
gr1.u_name= current.name; // replacefield name as per your requirement
gr1.u_number = current.number;
gr1.insert();
}
.
Please mark my response as correct answer or helpful if applicable
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-14-2022 02:36 AM
Hi Mahesh,
Thanks for the answer, is there a way I can also copy the related list from that table

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-14-2022 01:35 AM
Hi
Here is a script which you can use , just change the Table names and add the required fields :
var gr = new GlideRecord('incident');
gr.query();
while(gr.next()){
var gr1 = new GlideRecord('u_custom');
gr1.initialize();
gr1.u_name= gr.short_description;
gr1.u_number = gr.number;
gr1.insert();
}
OR
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.
Mark my answer correct & Helpful, if Applicable.
Thanks,
Sandeep
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-14-2022 02:41 AM
Hi,
so where are you stuck?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader