How to copy data from child table to parent table

Community Alums
Not applicable

Hi Team,

We have a child table "sn_ind_tmt_orm_order_line_item" with column as 'u_solution' ,its a string field and a parent table 'sn_csm_om_order_line_item' with column as 'temp_solution', its also a string field.

Now the requirement is to Delete the field on child table and before deleting it we need to copy the data from child column to parent column. Can you tell what script to write or how to achieve this?

1 ACCEPTED SOLUTION

Sandeep Rajput
Tera Patron
Tera Patron

Try this script.

 

var childLineItem = new GlideRecord('sn_ind_tmt_orm_order_line_item');

childLineItem.addEncodedQuery('u_solutionISNOTEMPTY');

childLineItem.query();

while(childLineItem.next()){

var parentLineItem = new GlideRecord('sn_csm_om_order_line_item');

if(parentLineItem.get(childLineItem.getValue('sys_id'))){

parentLineItem.setValue('temp_solution',childLineItem.getValue('u_solution'));

}

}

 

 

Caution: Please run this script initially for one record by setting the limit 1 childLineItem.setLimit(1); if the change looks good then run for all records. Also, run this script on sandbox first if changes are good then move to other instances.

Hope this helps.

View solution in original post

2 REPLIES 2

Sandeep Rajput
Tera Patron
Tera Patron

Try this script.

 

var childLineItem = new GlideRecord('sn_ind_tmt_orm_order_line_item');

childLineItem.addEncodedQuery('u_solutionISNOTEMPTY');

childLineItem.query();

while(childLineItem.next()){

var parentLineItem = new GlideRecord('sn_csm_om_order_line_item');

if(parentLineItem.get(childLineItem.getValue('sys_id'))){

parentLineItem.setValue('temp_solution',childLineItem.getValue('u_solution'));

}

}

 

 

Caution: Please run this script initially for one record by setting the limit 1 childLineItem.setLimit(1); if the change looks good then run for all records. Also, run this script on sandbox first if changes are good then move to other instances.

Hope this helps.

Community Alums
Not applicable

@Sandeep Rajput  I was able to write the simple script to achieve this but yours is also correct,