Is it possible to filter out cmdb_ci based on sys_class_name.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2018 11:20 PM
Hello All,
I need to filter out cmdb_ci list using query business rule.
var test=current.sys_class_name;
var test1=current.getValue('sys_class_name');
gs.log("&&&test"+test);
gs.log("@@@@test1"+test1);
if(current.sys_class_name=='cmdb_ci_server')
{ gs.log("&&&&&&before");
var encodedQuery='sys_class_name=cmdb_ci_server^operational_status=1';
current.addEncodedQuery(encodedQuery);
gs.log("&&&&&&after");
}
Am not able to enter to the if loop, because test and test1 are null and empty.
How can i solve this? Please advice.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2018 11:56 PM
Hi Swathi,
Try changing you if statement to something like if(gs.hasRole('itil')&& gs.isInteractive()){
The if statement in a before query BR is confirming the user querying the database meets the conditions, you then refine their query if they do.
if(gs.hasRole('itil')&& gs.isInteractive()){
var encodedQuery='sys_class_name=cmdb_ci_server^operational_status=1';
var qc = current.addEncodedQuery(encodedQuery);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2018 01:04 AM
Hi David,
Thanks for your quick reply.
My actual requirement is to filter out many sys_class_name...
Example:
if(current.sys_class_name=='cmdb_ci_server')
{
var encodedQuery='sys_class_name=cmdb_ci_server^operational_status=1';
current.addEncodedQuery(encodedQuery);
}
if(current.sys_class_name=='cmdb_ci_service')
{
var encodedQuery='sys_class_name=cmdb_ci_service^operational_status=1';
current.addEncodedQuery(encodedQuery);
}
if(current.sys_class_name=='u_cmdb_ci_application_service')
{
var encodedQuery='sys_class_name=u_cmdb_ci_application_service^operational_status=1';
current.addEncodedQuery(encodedQuery);
}
When i run this no result.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2018 06:03 AM
Try something like this:
if(gs.hasRole("itil") && gs.isInteractive()) {
var encodedQuery = 'operational_status=1^sys_class_name=cmdb_ci_server^ORsys_class_name=cmdb_ci_service^ORsys_class_name=u_cmdb_ci_application_service';
var qc = current.addEncodedQuery(encodedQuery);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2018 07:03 AM
I am not sure why you need to do the if conditions for checking the class names.If requirement is to filter out certain classes then just add the encoded query to the business rule .
current.addEncodedQuery(''sys_class_name=cmdb_ci_server^operational_status=1');
Add as many classes as you need using the condition builder and paste the encoded query, I do not think you need to check current.sys_class_name. I tested this and it works if I understood the requirements correct.