The CreatorCon Call for Content is officially open! Get started here.

How to copy data using fix script from one table to another table

Nagesh5
Tera Contributor

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

 

1 ACCEPTED SOLUTION

asifnoor
Kilo Patron

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

View solution in original post

3 REPLIES 3

Hayo Lubbers
Kilo Sage

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

asifnoor
Kilo Patron

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

Nagesh5
Tera Contributor

Thanks for the help and we can able to move the data with above script 

 

Thanks,

Nagesh