Imran1
Giga Guru

Hi All,

 

I was able to achieve the desired result using the below script 

 

var arr = [];
var trackerObj = {};
var gr = new GlideRecord('sys_history_line');
gr.addEncodedQuery("field=clint_owne^ORfield=do_actual_due_date^ORfield=do_due_dt^ORfield=do_in_sub_dt^ORfield=open_age^ORfield=u_assigned_to_list^ORfield=bucket^set.table=Table_Name");

gr.query();
while (gr.next()) {
var context = gr.set+ gr.field + gr.set.table + gr.user_name + gr.old + gr.getValue('new')+gr.user;
arr.push(context);
if(trackerObj[context]){
trackerObj[context].push(gr.sys_id.toString());
}
else{
trackerObj[context] = [];
trackerObj[context].push(gr.sys_id.toString());
}

}

for(var combination in trackerObj){
if(trackerObj[combination].length > 1)
gs.info(combination + ":" +trackerObj[combination].toString());
var deleteGR = new GlideRecord('sys_history_line');
deleteGR.addQuery('sys_id','!=',trackerObj[combination][0]);
deleteGR.addEncodedQuery('sys_idIN'+trackerObj[combination].toString());
deleteGR.query();
//gs.info('RowCount: '+deleteGR.getRowCount());
deleteGR.deleteMultiple();
}

 

Thank You for your response

Imran

 

View solution in original post