Fix Script:- Need to update date field on the record as date filed on the related record.

Chiranjeevi K
Tera Expert

Dear Team, I have requirement to update date filed on bulk records same as their related record and i need fix script for this, how ever i tried writing the script to update single record and it is working fine as expected.

I need a logic to achieve same functionality on bulk records , please find the below script and help..thank in advance !!

 

var gr = new GlideRecord('core_company');

gr.addQuery('sys_id','74638e021b720890e0e2fff7dc4bcb2d');

gr.query();

if(gr.next()){

    var gr1 = new GlideRecord('sn_vdr_risk_asmt_assessment');

    gr1.addQuery('sys_id','e433480387c6e51082390e59cebb3523');

    gr1.query();

    if(gr1.next()){

        gr.u_rating_valid_to = gr1.risk_rating_valid_to;

        gr.update();

    }

}

12 REPLIES 12

BharathChintala
Mega Sage

@Chiranjeevi K  Can you confirm what type of fields those both?

If my inputs have helped with your question, please mark my answer as accepted solution, and give a thumb up.
Bharath Chintala

both the filed types are "Date" 

@Chiranjeevi K 

 

Try below script 

var gr = new GlideRecord('core_company');

gr.addQuery('sys_id','74638e021b720890e0e2fff7dc4bcb2d');

gr.query();

if(gr.next()){

    var gr1 = new GlideRecord('sn_vdr_risk_asmt_assessment');

    gr1.addQuery('sys_id','e433480387c6e51082390e59cebb3523');

    gr1.query();

    if(gr1.next()){

var dat = new GlideDateTime(gr1.risk_rating_valid_to);

        gr.u_rating_valid_to =dat.getDate();

        gr.update();

    }

}

If my inputs have helped with your question, please mark my answer as accepted solution, and give a thumb up.
Bharath Chintala

Chetan Mahajan
Kilo Sage
Kilo Sage

Hello @Chiranjeevi K ,

                                     You can use as below 

var gr = new GlideRecord('core_company');
gr.addQuery('sys_id','74638e021b720890e0e2fff7dc4bcb2d'); // you can remove this line or you can use any filter condtion if you want
gr.query();
while(gr.next()){
    var gr1 = new GlideRecord('sn_vdr_risk_asmt_assessment');
    gr1.addQuery('sys_id', gr.getUniqueValue() ); // beleiving this is refering to gr 
    gr1.query();
    if(gr1.next()){
        gr.u_rating_valid_to = gr1.risk_rating_valid_to;
        gr.update();
    }

}

 

Kindly mark correct and helpful if applicable