Reference Qualifier to filter CI using a Property

Mickey_Cegon
Tera Expert

We would like to use a reference qualifier to limit the CI's that are displayed, using a Property that holds the classes that we want available. Currently, we have the Class field on the forms we use, and we filter the classes using a script include that has an array of classes we have to update. We'd like to remove the Class field, and just use the ref qual to filter instead.

 

I created a property called glide.ciclass.available, and in the value field, I put one class, just to test out my reference qualifier. I used u_cmdb_ci_system,
which is our main list of systems we have as CIs. Then, I created a Script Include, that queries the cmdb_ci table for only CI's that have a matching class. So, theoretically, I should only get a list of about 375 CIs, which is all that is in that specific table. I added the reference qualifier to the table,
but I'm still coming back with all CI's and not just the systems.

 

At this point, I've gone through so many iterations of script includes and reference qualifiers, that I just threw up my hands and decided to ask for help. I thought this would be easy, but the logic is escaping me.

 

So, the value in the property is

 

u_cmdb_ci_system

 

Here's the latest version of my script include:

 

availableCIClass();

function availableCIClass(){

var ci   = new GlideRecord('cmdb_ci');

var ciClassListProperty = gs.getProperty('glide.ciclass.available');

var ciMatch = new Array();

ci.addQuery('sys_class_name', 'IN', ciClassListProperty);

ci.query();

while (ci.next()) {  

  if (ciMatch.length > 0){

    var id = ci.sys_id.toString();

    return ciMatch(id);

  }

}

}

 

Can someone please point me in the correct direction?

 

Thanks!

 

Mickey Cegon

FBL Financial Group, Inc.

22 REPLIES 22

This is a scriptInclude I have just put into my DEV instance and it is called getCiClasses


i have added a log line for testing as well.



function getCiClasses() {



      var ciClassListProperty = gs.getProperty('glide.ciclass.available');


      //var ciClassListProperty = 'cmdb_ci_server;cmdb_ci_netgear;cmdb_ci_computer';


      var ciArr = ciClassListProperty.split(';');


      var str = '';


      for (i=0; i<ciArr.length;i++)


      {


      if (str == '')


              str += 'sys_class_name='+ciArr[i];


      else


              str += '^sys_class_name='+ciArr[i];


      }


      gs.log('LongReferenceQualifier - getCiClasses : ' + str);


      return str;


}


 





No problems here


I tried it in Chrome, no error. So, must be an IE 11 thing. Thanks!


Ah, I use FF or Chrome.


IE is a place of last resorts for me.


So, the ref qual works, but only if I have just one class listed in the property. If I add more than one, it fails, and shows no CI's when I bring up the list. I've tried to separate the classes using a comma and a semi-colon, and neither option works. Am I missing something?


If you run it as a background script and read the value, what does the gs.print return ?


could try



var ciArr = ciClassListProperty.toString().split(';');