Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to copy data to parent field table

Community Alums
Not applicable
Hi Team,
 
"u_solution"  is a field in child table
"sn_ind_tmt_orm_order_line_item" is the child table is in scope 'abc'
"u_temp_solution" is a field on parent table
"sn_csm_om_order_line_item" is parent table for reference which is in scope 'xyz'
 

I have written below Fix script in scope 'xyz' to copy data from a field on child table to the field on parent table but its not getting copied.

var gr=new GlideRecord('sn_ind_tmt_orm_order_line_item');
gr.query();
while(gr.next()){
    if(gr.u_solution!='' && gr.u_temp_solution==''){
gr.u_temp_solution=gr.u_solution;
gr.update();
    }
1 ACCEPTED SOLUTION

Tai Vu
Kilo Patron
Kilo Patron

Hi @Community Alums 

Let's try the below script.

var grChild = new GlideRecord('sn_ind_tmt_orm_order_line_item');
grChild.addNotNullQuery('u_solution');
grChild.query();
while(grChild.next()){
    var grParent = new GlideRecord('sn_csm_om_order_line_item');
    grParent.addQuery('sys_id', grChild.parent) //Replace the Parent field name from the child table.
    grParent.query();
    if(grParent.next()){
        grParent.u_temp_solution = grChild.u_solution;
        grParent.update();
    }
}

 

Let me know if it works for you.

 

Cheers,

Tai Vu

View solution in original post

1 REPLY 1

Tai Vu
Kilo Patron
Kilo Patron

Hi @Community Alums 

Let's try the below script.

var grChild = new GlideRecord('sn_ind_tmt_orm_order_line_item');
grChild.addNotNullQuery('u_solution');
grChild.query();
while(grChild.next()){
    var grParent = new GlideRecord('sn_csm_om_order_line_item');
    grParent.addQuery('sys_id', grChild.parent) //Replace the Parent field name from the child table.
    grParent.query();
    if(grParent.next()){
        grParent.u_temp_solution = grChild.u_solution;
        grParent.update();
    }
}

 

Let me know if it works for you.

 

Cheers,

Tai Vu