Query cmdb_rel_ci table and get parent records which contains terminated on field

rambo1
Tera Guru

Hi,

I am query cmdb_rel_ci table, with filter conditions as below:

child.class = aws_datacenter or azuredatacenter

I also want to add one more condition :

child.terminated_on is in last 24 hours.

Problem is, terminated on field is not there on cmdb_ci table, it is there only on few tables and I want only those record which have that field.

How do I write query?

I am trying some script as below :

var query = 'child.sys_class_name=cmdb_ci_aws_datacenter^ORchild.sys_class_name=cmdb_ci_azure_datacenter';
var gr = new GlideRecord('cmdb_rel_ci');
gr.addEncodedQuery(query);
gr.query();
while(gr.next())
{
var cs = new GlideRecord('cmdb_ci_vm_object');
cs.addQuery('sys_id',gr.parent.sys_id);
cs.query();
while(cs.next())
{
if(cs.terminated_on.isValid() == true)
{
gs.print(cs.name);
}
}
}

getting the below result:

ompacting large row block (file.write: cmdb_rel_ci 10000 rows 160000 saveSize)

Any suggestions?

11 REPLIES 11

click on the small box and attach to other class 

find_real_file.png

Hi Rambo,

 

Kindly mark my response correct and helpful if my suggestion helped you,


Thanks

Murali