Copy records from one table to another tables using script.

Peter Wood
Kilo Guru

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?

1 ACCEPTED SOLUTION

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();

 

}

View solution in original post

14 REPLIES 14

Yeah you are correct,

Actually my custom number field is of integer type thats why I faced problem.later I investigate and got to know that both fields types are different so I change that and it is giving me correct result.

Thanks Harshvardhan

Sorry to disturb you again,

So far I have tried this in background script can we do this using another script technique?As I heard that background data insertion is not long lasting?Is it right or wrong?

Thanks,

Peter.

What is your exact requirement? Should this be done reguraly? Or is it a one time thing?

You could use for example:
- Background script (one time)
- Fix script (can be run in background, and if wanted mutliple times)
- Scheduled job (though my guess is this is a one time thing? because performing the script again would just make duplicate record?)
- Etc.

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

LinkedIn

Thanks Mark,

But it is not for one time it is for several times.

Then Fix Script could be fine. Fix Script is saved, so easy to execute again, at any moment you want.

Though, concerning your current scripting, what about duplicates? I mean with the current scripting, you are just copying every record every time?

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

LinkedIn