Remove duplicates in incident metric table Report

poojitha bn
Giga Expert

Hi Experts,

I have to remove duplicates in Incident_metric table report.

Currently I am trying to remove using script include but I couldn't achieve it. Can anybody help me doing this.

Report:

find_real_file.png

Script Include:

find_real_file.png

Can anyone help me to fix it.

 

1 ACCEPTED SOLUTION

Hi Poojitha,

The above code will not work as it returns incident number which is same for duplicate records so the report will display duplicate records. As per your screenshot, if the function returns 'FVSD_2337' then report will still display all three records as they all satisfy the condition.

So you need to return unique value like sys_id of one of the duplicate so the report doesn't display the other duplicate.

 

Let me know if it helps.

View solution in original post

13 REPLIES 13

When I run  below code in BG script its working but not in script include something fishy

var gr = new GlideAggregate('incident_metric');
gr.addEncodedQuery('mi_definition=35f0791ac0a808ae008f0a2b1dc1030c^mi_field=assigned_to^inc_assignment_group=295349721b6f2b00a38b64606e4bcbc2^inc_assigned_toISNOTEMPTY^inc_active=true');
gr.groupBy('inc_number');
gr.query();
var arr=[];
var count = 0;
while(gr.next()){
arr.push(gr.inc_number.toString());
count++;
}
var noDuplicates = new ArrayUtil().unique(arr).toString();
gs.print("inc is" + noDuplicates);
gs.print("count" +count);

Try the following. Also, in the report filter condition, change incident_number with sys_id

var arr = [];

var sysId = '';
var gr = new GlideAggregate('incident_metric');
gr.addEncodedQuery('mi_definition=35f0791ac0a808ae008f0a2b1dc1030c^mi_field=assigned_to^inc_assignment_group=295349721b6f2b00a38b64606e4bcbc2^inc_assigned_toISNOTEMPTY^inc_active=true');
gr.addNotNullQuery('inc_number');
gr.groupBy('inc_number');
gr.query();

while(gr.next()){
sysId = gr.getValue("sys_id");
if(arr.indexOf(sysId)==-1){
arr.push(sysId);
}
}

return arr.join(",");

 

Let me know if it helps.

Hi Ankur,

I tried above one by keeping sys_id in report filter condition, But no luck.

I have tried to get unique value in array as below code but didnt worked

var processResults = Class.create();
processResults.prototype = Object.extendsObject(AbstractAjaxProcessor,{
initialize: function() {
},
UniqueData: function(){
var dupRecords = [];
var gr = new GlideAggregate('incident_metric');
 gr.addEncodedQuery('mi_definition=35f0791ac0a808ae008f0a2b1dc1030c^mi_field=assigned_to^inc_assignment_group=295349721b6f2b00a38b64606e4bcbc2^inc_assigned_toISNOTEMPTY^inc_active=true');
gr.groupBy('inc_number');
gr.query();
while (gr.next()) {
          dupRecords.push(gr.inc_number.toString());
    }
var nodup = this.unique(dupRecords);
return nodup;
},
unique: function(a1){
var a = [];
var l = a1.length;
for (var i = 0; i < l; i++) {
for (var j = i + 1; j < l; j++) {
if (a1[i] === a1[j])
j = ++i;
}
a.push(a1[i]);
}
return a;
},
type: 'processResults'

});

Hi Poojitha,

The above code will not work as it returns incident number which is same for duplicate records so the report will display duplicate records. As per your screenshot, if the function returns 'FVSD_2337' then report will still display all three records as they all satisfy the condition.

So you need to return unique value like sys_id of one of the duplicate so the report doesn't display the other duplicate.

 

Let me know if it helps.

Hi Ankur,

Thanks for the response we already answered the same for client 🙂