- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-21-2019 03:00 AM
I have two tables "ABC" and "PQR".Both table contains same fields. In ABC table I have 100 records I want to pull all 100 records in table PQR using script.How to do that?
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-21-2019 03:34 AM
i tested with below code in my persona instance. i create custom number field on my custom table and its string type field and it has copied the incident number to the custom number field.
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();
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-21-2019 03:13 AM
you can use below code here to copy the data from one table to another table.
Sample code:
var gr = new GlideRecord('abc');
gr.query();
while(gr.next()){
var gr1 = new GlideRecord('PQR');
gr1.initialize();
gr1.<field name> = gr.<field name>;
gr1.insert();
}
Note: add the field name which you want to copy here.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-21-2019 03:29 AM
Thanks Harshvardhan,
I tried this in background script it is working but I am facing one problem in it.
I have system generated number fields(which generates auto number) but is it not getting copied in custom number field,what is the problem.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-21-2019 03:34 AM
Hi there,
Do you mean you have on both your ABC and PQR tables auto-number set? And PQR now generates a new number? Or is your question different?
Do you want the old number from ABC, to be used in PQR? Do note: using different Numbers will make the record not findable through the direct search.
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
---
LinkedIn
Community article list
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-21-2019 03:34 AM
i tested with below code in my persona instance. i create custom number field on my custom table and its string type field and it has copied the incident number to the custom number field.
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();
}