Dynamicly restrict list of CI choices based on selected category/subcategory - Incident

debmcdaniel
Giga Contributor

All,

I have a business requirement to restrict the list of CI choices based on selected category/subcategory on the incident form.

So for example, we have a category = Hardware and a Subcategory = Computer. In the configuration item field I'd like to have only configuration items found in the cmdb_ci_computer table display in the list of choices for the Configuration Item list.

find_real_file.png

I've been able to make this happen using the following:

find_real_file.png

However, I need this to be more dynamic so that it filters the CI list based on the subcategory selected. We have determined which CI classes will display under Hardware (for example, computer, printer, server, etc) so when a person selects Computer the CI list should only include the CIs contained within the cmdb_ci_computer table; when Server is selected the CI list should only contain all the CIs associated with cmdb_ci_server, etc.

Our goal is to use CI-based routing for task group assignments (Incident, Problem, Change). to do so we'd like to restrict the CI list to just the items found based on the category/subcategory options selected.

1 ACCEPTED SOLUTION

Hi Daniel,



I did tested the piece of code in my instance , and the below code is working fine.



var RefQualUtils = Class.create();
RefQualUtils.prototype = {
      initialize: function() {
      },


  getCIRefQual : function(current) {
  var filter = '';
  gs.addInfoMessage(current.category);
  if(current.category == 'software') {
  return "sys_class_name=cmdb_ci_appl";
  }
  },



      type: 'RefQualUtils'
};



Note : the current.category takes "software" ( Value in the category choice list") not "Software"


View solution in original post

6 REPLIES 6

Mihir Mohanta
Kilo Sage

You have to use advanced reference qualifier for this requirement.


Please go through below thread.


To filter CI on Incident based on Category




http://wiki.servicenow.com/index.php?title=Reference_Qualifiers#gsc.tab=0


Ok, I followed the instructions from the thread provided but I'm not getting what I need.



Here is what I have under the Advanced Reference Qualifier for the Configuration Item on the Incident Form:


find_real_file.png



Here is the modified script include that I used to *attempt* to create a dynamic filter that would only return records in the cmdb_ci_appl table:



var RefQualUtils = Class.create();


RefQualUtils.prototype = {


  initialize: function() {


  },



  getCIRefQual : function(current) {


  var filter = '';


  if(current.category == 'Software') {
  return "sys_class_name = cmdb_ci_appl";
  }


  else {


  filter = ''; // Add the default filter for other cases.


  }


  return filter;


  },



  type: 'RefQualUtils'


};



Where did I go wrong?



Hi Daniel,



I did tested the piece of code in my instance , and the below code is working fine.



var RefQualUtils = Class.create();
RefQualUtils.prototype = {
      initialize: function() {
      },


  getCIRefQual : function(current) {
  var filter = '';
  gs.addInfoMessage(current.category);
  if(current.category == 'software') {
  return "sys_class_name=cmdb_ci_appl";
  }
  },



      type: 'RefQualUtils'
};



Note : the current.category takes "software" ( Value in the category choice list") not "Software"


I also have similar problem. I tried your code. But it is showing Computers as class name in my configuration item field. But I need to show Linux Server or Windows Server.

 

 

var RefQualUtils = Class.create();
RefQualUtils.prototype = {
initialize: function() {
},
getCIRefQual : function(current) {
var filter = '';
if(current.subcategory == 'Windows Server') {
return "sys_class_name=cmdb_ci_win_server";
}
else if(current.subcategory == 'Linux Server'){
return "sys_class_name=cmdb_ci_win_server";
}

},

 

type: 'RefQualUtils'
};

 

This is the code. 

 

Also I tried to write fix script for the same.

var gr=new GlideRecord('incident');
  var c=gr.getValue('subcategory');
  if(c=='Linux Server'){
    current.addEncodeQuery('sys_class_name=cmdb_ci_linux_server');
  }
  else if(c=='Windows Server'){
    current.addEncodeQuery('sys_class_name=cmdb_ci_win_server');
  }

 

But both the time I am getting list of Computer as a class.