- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-30-2022 09:14 PM
Hello Community,
We have m2m table between two table 1.is global(Status of the Airplanes) and 2nd is scoped table(Flights Airplane) and we have data in the m2m table. only two reference field values in the m2m form one is Status of the number and other one is Airplane number
As part of our requirement we have converted 1st global application table to scoped application(Status of the Airplanes) and created m2m relationship as well same.
Now we want to copy the data from global m2m table to scoped m2m table. Could you please help anyone with the fix script to achive this with missing any fields data
And also please note above m2m table maped as a related list in scoped application.
Thanks in Advance
Thanks,
Nagesh
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-31-2022 06:21 AM
Hi Nagesh,
You need to write custom script to copy the data from old to new table.
var gr = new GlideRecord("old_table");
gr.query();
while(gr.next()) {
var newGr = new GlideRecord("new_table");
newGr.initialize();
newGR.field_name = gr.field_name.toStrin();
//add remaining fields as is
newGr.insert();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-31-2022 01:22 AM
Hi Nagesh,
Something like this? Untested, but you'll probably get the idea.
var grAirplaneM2M = new GlideRecord('YourAirplaneM2MTableName');
grAirplaneM2M.addQuery('SomeField','SomeValue'); //You might want some conditions
grAirplaneM2M.query();
while(grAirplaneM2M.next()){
var grAirplane = grAirplaneM2M.TheFieldNameContainingTheReferenceOnYouM2MTableToAirplane.getRefRecord();
var grFlightAirplane = grAirplaneM2M.TheFieldNameContainingTheReferenceOnYouM2MTableToFlightAirplane.getRefRecord();
if(grAirplane && grFlightAirplane){
grFlightAirplane.setValue('fieldname', grAirplane.getValue('fieldname'));
//all the fields you like to copy
grFlightAirplane.update();
}
}
You could also do it via a Flow in the flow designer if your scripting is not that well. Query all the records and you can map the fields in the update action.
Regards,
Hayo

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-31-2022 06:21 AM
Hi Nagesh,
You need to write custom script to copy the data from old to new table.
var gr = new GlideRecord("old_table");
gr.query();
while(gr.next()) {
var newGr = new GlideRecord("new_table");
newGr.initialize();
newGR.field_name = gr.field_name.toStrin();
//add remaining fields as is
newGr.insert();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-31-2022 07:16 AM
Thanks for the help and we can able to move the data with above script
Thanks,
Nagesh