Need to filter reference field with CMDB table

rajibosss11
Tera Contributor

Hi Team,

I have an Incident form with a Subcategory field containing the following options: Hardware, Application, and Database.

Below the Subcategory field, we have a Configuration Item reference field (referencing the cmdb_ci table). I would like to apply dynamic filtering so that:

  • When the Subcategory is set to Hardware, the Configuration Item field should only show records from the cmdb_ci table where the class is Computer.

  • When the Subcategory is set to Application, it should only show records where the class is Application.

  • Similarly, for Database, it should only show records where the class is Database.

and in configuration item we have already some reference qualifier

Could you please guide me on how to achieve this?

6 REPLIES 6

RaghavSh
Kilo Patron

configuration item field is on task table ,  Do you have a dictionary override for incident table?

If yes can you share that?


Raghav
MVP 2023

rajibosss11
Tera Contributor

No dont have dictionary over ride please add 

Try adding below in cmdb_ci dictionary override for incident table:

 

1. javascript:new getCI().getClassCI(current.subcategory);

 

2. Create Script include named getCI with below code:

 

getClassCI :  function(subcat){
 var arr = [];
 var ci = new GlideRecord('cmdb_ci');
if(subcat == 'hardware'){ // verify backend value of subcategory
ci.addQuery('sys_class_name' , 'cmdb_ci_computer'); 
ci.query();
while(ci.next()){
arr.push(ci.getUniqueValue());
}
}
if(subcat == 'database'){// verify backend value of subcategory
ci.addQuery('sys_class_name' , 'cmdb_ci_database'); 
ci.query();
while(ci.next()){
arr.push(ci.getUniqueValue());
}
}
if(subcat == 'application'){/ / verify backend value of subcategory
ci.addQuery('sys_class_name' , 'cmdb_ci_appl'); 
ci.query();
while(ci.next()){
arr.push(ci.getUniqueValue());
}
}
return arr;
}

 


Raghav
MVP 2023

1. javascript:new getCI().getClassCI(current.subcategory);

this line not work