Report Filter based on JavaScript

Jason Stuart
Tera Expert

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

1 ACCEPTED SOLUTION

Abhinay Erra
Giga Sage

Code looks right. Make sure the script include is client callable. From the script include code I don't think it is checked.

View solution in original post

17 REPLIES 17

dvp
Mega Sage
Mega Sage

Are you trying to group CI's by IP address?

I am trying to do it by the whole table.

But I want it displayed by Class

so

              

 ServersComputersNetworkGearTotal
IP Address 11012
IP Address 21001
IP Address 31113

I want to say, if the total is One - filter it out of the report.

I don't think you need a script for that

Here is how you can configure in a report

find_real_file.png

I want to say if the total,or count is 1, ignore the record.