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

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.

find_real_file.png

 

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.

Script part in the report filter is incorrect. It should be this

javascript: new GetDupes().GetDupes("cmdb_ci","ip_address")

Still not quite working.... I think its almost there - and appreciate your help...

 

find_real_file.png

 

You are not seeing anything in the report yet?