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

Suryadeep
Tera Contributor

In Incident form, when Category is Selected as Hardware and subcategory selected as Windows Server or Linux Server .Configuration Item field should auto populate  list of class of Windows Server CI or Linux Server CI. 

 

For that I have done two thing:

First from Fix Script:

 

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 after executing it, I am getting list of computers only. Similar type of thing I tried to do from Business rule. But I got the similar result of list of computer only.
 
Then Second approach I tried through configure dictionary of Configuration Item. In that I wrote dynamic creation script.
 
 

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'
};

 

 

After executing it, I still getting configuration item list of computers only. Please help in this issue.

 
3 REPLIES 3

Harish KM
Kilo Patron
Kilo Patron

Hi @Suryadeep here is the code

getCiList: function(subcategory) {
var className;
if(subcategory == 'Windows Server')// ensure subCategory value matches here
{
className='cmdb_ci_win_server'; // set classname to windows server
}
else{
className='cmdb_ci_linux_server'; // set classname to Linux server
}

var CIList = [];
var ci = new GlideRecord('cmdb_ci_server');
ci.addQuery('sys_class_name', className);
ci.query();
while (ci.next()) {
CIList.push(ci.getValue('sys_id'));
}

return "sys_idIN" + CIList.join(',');
},

call this on CI field's reference qualifier on incident table
javascript:new ScriptIncludeName().getCiList(current.subCategory);

Regards
Harish

 

Suryadeep
Tera Contributor

Still showing Computer and Printers in CI field.