Fix script.

Thalavai m
Tera Contributor

Hi All,

we are having a requirement that we have to create a new field and copy records for old field to the new field and make the old field Inactive we have tried to copy the records using Fix script but its not copying the records can anyone help me to create a script please. 

this is the script we have tried. 

 

var gr = new GlideRecord('cmdb_ci_business_app');
gr.addEncodedQuery('u_ug_rtoISNOTEMPTY^u_ug_rpoISNOTEMPTY');
gr.query();
while (gr.next()) {
        gr.setValue('u_rto', 'u_ug_rto');
    gr.setValue('u_rpo', 'u_ug_rpo');
        gr.update();
    }

1 ACCEPTED SOLUTION

Danish Bhairag2
Tera Sage
Tera Sage

Hi @Thalavai m ,

 

Please try below code. Hope both field type are same in ur table

var gr = new GlideRecord('cmdb_ci_business_app');
gr.addEncodedQuery('u_ug_rtoISNOTEMPTY^u_ug_rpoISNOTEMPTY');
gr.query();
while (gr.next()) {
        gr.u_rto = gr.u_ug_rto; \\ this line will copy the value from 1 field to another
    gr.u_rpo = gr.u_ug_rpo;
gr.u_ug_rto = ''; \\post copying it will make the other field empty
gr.u_ug_rpo = '';
        gr.update();
    }

 

Thanks,

Danish

View solution in original post

5 REPLIES 5

Danish Bhairag2
Tera Sage
Tera Sage

Hi @Thalavai m ,

 

Please try below code. Hope both field type are same in ur table

var gr = new GlideRecord('cmdb_ci_business_app');
gr.addEncodedQuery('u_ug_rtoISNOTEMPTY^u_ug_rpoISNOTEMPTY');
gr.query();
while (gr.next()) {
        gr.u_rto = gr.u_ug_rto; \\ this line will copy the value from 1 field to another
    gr.u_rpo = gr.u_ug_rpo;
gr.u_ug_rto = ''; \\post copying it will make the other field empty
gr.u_ug_rpo = '';
        gr.update();
    }

 

Thanks,

Danish

thank You, Danish Bhairag2 Its working. 

Mark Manders
Mega Patron

What kind of fields are these? Just string fields, or references?

 


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

And it could be your 'and' condition as well. Try this one: 

var busApp = new GlideRecord('cmdb_ci_business_app');
busApp.addEncodedQuery('u_ug_rtoISNOTEMPTY^ORu_ug_rpoISNOTEMPTY');
busApp.query();
while(busApp.next()){
    busApp.setValue('u_rto','u_ug_rto');
    busApp.setValue('u_rpo','u_ug_rpo');
    busApp.update()
}

 


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark