Custom filter on related list

grosch
Mega Expert

On my model table there's a "Related List" of "Hardware->Model" which shows, shocker, all the hardware with the given model.   I'd like to add a second related list of Hardware->Model, but I want to set the filter to be all devices with the current model, where the class does not match the "CMDB CI Class" specified on the model.  

In other words, that would show me all our hardware where the class specified is most likely incorrect, and our Asset Managers need to investigate.

Is that possible to do, and if so, how?

1 ACCEPTED SOLUTION

coryseering
ServiceNow Employee
ServiceNow Employee

Hi Scott,



You just need to define a new Relationship for the tables, and then add that as a new Related List.


Creating Defined Related Lists - ServiceNow Wiki



Just remember this very important point:


  • When scripting your condition, current is the record to which you want to add queries while parent is the main record being displayed.

View solution in original post

7 REPLIES 7

coryseering
ServiceNow Employee
ServiceNow Employee

Hi Scott,



You just need to define a new Relationship for the tables, and then add that as a new Related List.


Creating Defined Related Lists - ServiceNow Wiki



Just remember this very important point:


  • When scripting your condition, current is the record to which you want to add queries while parent is the main record being displayed.

I did something wrong apprently.   I did this:



Applies to table:   cmdb_model


Queries from table: cmdb_ci_hardware


Query with:



current.addQuery('sys_class_name', '!=', (function () {


  var gr = new GlideRecord('cmdb_hardware_product_model');


  gr.addQuery('inactive', false);


  gr.addQuery('label', parent.cmdb_ci_class.toString());


  gr.query();


  gr.next();


  return gr.value.toString();


})());



When I then add the related list to the model table, I see the tab, but the custom query is not there.


rob_pastore
ServiceNow Employee
ServiceNow Employee

Wouldn't it be easier to create a filter for the existing related list.   So it defaults to all - and then you can go to filter> and select the one for class?


That would require somebody to add the filters every time though.   I want it to just default to what I'm looking for.