I'm running a background script to update the old records of a sys_id requested_for column to the custom column u_opened_for and it's returning this message when I run the script and it just updates some records

1231
Tera Contributor

var gr = new GlideRecord('sc_req_item');
    gr.addEncodedQuery('u_opened_for=NULL^ORDERBYu_opened_for')
    gr.query();
    while (gr.next()){
    gr.u_opened_for = gr.variables.requested_for.getDisplayValue();
    gr. setWorkflow ( false ) ;
    gr.update();

    }

    

 

find_real_file.png

7 REPLIES 7

I have tried the below code: Its working perfectly fine.

var gr = new GlideRecord('sc_req_item');
gr.addEncodedQuery('u_opened_for=NULL^ORDERBYu_opened_for');
gr.query();
while(gr.next()){
gr.u_opened_for = gr.getDisplayValue('request.requested_for');
gr.u_opened_for_ref.setDisplayValue(gr.getDisplayValue('request.requested_for'));
gr.update();
}

 

Attached the output as well.

The main problem was that gr.variables.requested_for wasn't fetching the values from sc_req_item table.

 

Please mark my answer as correct if you found it helpful.

 

Regards,

Nikhil.

I have tried the below code: Its working perfectly fine.

var gr = new GlideRecord('sc_req_item');
gr.addEncodedQuery('u_opened_for=NULL^ORDERBYu_opened_for');
gr.query();
while(gr.next()){
gr.u_opened_for = gr.getDisplayValue('request.requested_for');
gr.u_opened_for_ref.setDisplayValue(gr.getDisplayValue('request.requested_for'));
gr.update();
}

 

Attached is the output as well.

The main problem was that gr.variables.requested_for wasn't fetching the values from sc_req_item table.

 

Please mark my answer as correct if you found it helpful.

 

Regards,

Nikhil.

suvro
Mega Sage
Mega Sage

Just run this

 

var gr = new GlideRecord('sc_req_item');
    gr.addEncodedQuery('u_opened_for=NULL^ORDERBYu_opened_for')
    gr.query();
    while (gr.next()){
    gr.u_opened_for = gr.variables.requested_for;
    gr.setWorkflow(false) ;
    gr.update();

    }