Reference Qualifier to filter CI using a Property

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-14-2014 02:08 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-17-2014 08:14 AM
If I assume that your list is a delimited list, semi colon, then something like the following shoud work for you
//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]
}
//return str;
gs.print(str);
You get
sys_class_name=cmdb_ci_server^sys_class_name=cmdb_ci_netgear^sys_class_name=cmdb_ci_computer
Enable / disable lines 1/2 if you are just testing with hard coded info or your property
enable / disable line 13/14 if you are running as a script and want to return data, or just print out via a backgroun script to check what query line you will have returned
cheers

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-17-2014 08:17 AM
Thanks! I'll try that out.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-17-2014 08:36 AM
I'm getting an error when I uncomment line 13, JavaScript parse error at line (13) column (7) problem = invalid return
Is there something I need to fix to get that error to go away?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-17-2014 08:41 AM
the gs.print(str) is when testing in a background script (you can check what is returned)
once you are happy, you put it as a Script Include and switch from gs.print(str) to return str as you are then returning the string value from the Script Include
you could change gs.print(str) to gs.log(str) so you can see what is being returned in the logs incase you are still not seeing what you expect

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-17-2014 08:45 AM
I did have it as my script include, and that's where I'm getting the error. I used the other lines in background script, and came back w/the correct values. but, I can't save the script include, because it has the error in it about the invalid return.
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];
}
return str;
//gs.print(str);