How to optimise the fix script on RITM table which is going to update the 8 lakh records ?

raj99918
Tera Contributor

Hi 

 

I have written below 2 fix scripts which is going to update the 4 fields on RITM table for 8 lakh records fix script is working fine I have tested it in lower instance which having 30k records but I checked the prod it have 8 lakh records so am afraid to run it on prod so I want your suggesting on my below 2 scripts:

 

Below script is to set the close and closed by fields:

 

var ritm = new GlideRecord("sc_req_item");
ritm.addEncodedQuery("stateIN3,4,7^active=false^closed_atISEMPTY^ORclosed_byISEMPTY");
ritm.query();
while (ritm.next()) {
    var updatedOn = new GlideDateTime(ritm.sys_updated_on);
    var user = ritm.sys_updated_by;
    var id = new GlideRecord('sys_user');
    id.addQuery('user_name', user);
    id.query();
    while (id.next()) {
        ritm.closed_by = id.sys_id; // Closed By
    }
   ritm.closed_at = updatedOn; // Closed time
    ritm.setWorkflow(false);
    ritm.autoSysFields(false);
    ritm.update();
}
gs.info("Number of records to updated for closed and closed by: "+ritm.getRowCount());
 
Below script is to set the Duration and Business Duration fields:
 
 var schedule = new GlideSchedule(gs.getProperty('x_og_schedule_id')); // Default calendar of the system (Workday 8:00 - 5:00)
var ritm = new GlideRecord("sc_req_item");
ritm.addEncodedQuery("stateIN3,4,7^active=false^calendar_durationISEMPTY^ORbusiness_durationISEMPTY");
ritm.query();
while (ritm.next()) {
    var createdOn = new GlideDateTime(ritm.sys_created_on.getValue());
     var closedat = new GlideDateTime(ritm.closed_at.getValue());
    var duration = gs.dateDiff(createdOn, closedat, false);
    ritm.calendar_duration = duration;  // Duration

var opened_at = ritm.opened_at.getGlideObject();
var closed_at = ritm.closed_at.getGlideObject();
var business = schedule.duration(opened_at, closed_at);
ritm.business_duration = business; // Business Duration
    ritm.setWorkflow(false);
    ritm.autoSysFields(false);
    ritm.update();

    gs.info("Total Records to update the Duration and Business Duration: "+ritm.getRowCount());
}