
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2019 04:50 AM
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:
Script Include:
Can anyone help me to fix it.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2019 03:13 AM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2019 05:56 AM
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);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2019 06:15 AM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2019 08:08 AM
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'
});

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2019 03:13 AM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2019 03:35 AM
Hi Ankur,
Thanks for the response we already answered the same for client 🙂