- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-13-2019 11:25 AM
Good Afternoon,
I have been working for the last day trying to figure out how to make a filter based on JavaScript for a report. Here is what I am trying to do. Search all CI's (cmdb_ci) table, and look for duplicate IP Addresses. I used a Multi Pivot Table to get this report, and of course the performance was hindered in my instance - so this approach is not optimal. I than wanted to filter out those rows that just had a single instance of an IP Address.
Here is the javascript I attempted to use.
var GetDupesTake2 = Class.create();
GetDupesTake2.prototype = {
initialize: function() {
},
GetDupesTake2: function(tablename, dupefield) {
var q = new GlideAggregate(tablename);
q.addAggregate('COUNT', dupefield); //aggregate to count values in whatever field is passed as dupeField
q.addHaving('COUNT', dupefield, '>', '1');
q.query();
var listOfDupes = []; //build array to push the results into
while (q.next()) {
listOfDupes.push(q.getValue(dupefield)); //Push the value of the dupe field to the array
jslog('I did something');
}
return listOfDupes;
},
type: 'GetDupesTake2'
};
for the Filter I had it set to
IP Address is one of javascript:GetDupesTake2('cmdb_ci','ip_address);
Can someone please point me in the right direction? The above is not working.
Thanks in Advance!
Jason
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-13-2019 01:43 PM
Code looks right. Make sure the script include is client callable. From the script include code I don't think it is checked.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-13-2019 01:43 PM
Code looks right. Make sure the script include is client callable. From the script include code I don't think it is checked.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-14-2019 04:03 AM
and this is the new code.
var GetDupes = Class.create();
GetDupes.prototype = Object.extendsObject(AbstractAjaxProcessor, {
GetDupes: function(tablename, dupefield) {
var q = new GlideAggregate(tablename);
q.addAggregate('COUNT', dupefield); //aggregate to count values in whatever field is passed as dupeField
q.addHaving('COUNT', dupefield, '>', '1');
q.query();
var listOfDupes = []; //build array to push the results into
while (q.next()) {
listOfDupes.push(q.getValue(dupefield)); //Push the value of the dupe field to the array
jslog('I did something');
}
return listOfDupes;
},
type: 'GetDupes'
});
does this look better? You were right about the script include. It was Client Callable, but I think I checked that box AFTER I created the function.
The screenshot above are the results I am getting, I think I am still missing something.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-14-2019 07:26 AM
Script part in the report filter is incorrect. It should be this
javascript: new GetDupes().GetDupes("cmdb_ci","ip_address")
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-14-2019 07:42 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-14-2019 07:48 AM
You are not seeing anything in the report yet?