The CreatorCon Call for Content is officially open! Get started here.

how to get the childs "operational status" of cmdb_ci_appl table

rick48
Tera Contributor

need to get the childs "operational status" of cmdb_ci_appl table

  i used the below script but i couldn't get the value of child, its showing undefined in gslog.

was my script correct?

if(source.u_operational_status=="Retired")
	{
		var grr=new GlideRecord("cmdb_rel_ci");
		grr.addQuery("parent","source.u_operational_status");
		grr.Query();
		while(grr.next());
		{
			
			if(grr.child.operational_status.getDisplayValue()!="Retired")
				{
					gs.log(grr.child.operational_status.getDisplayValue());
					ignore=true;
				}
		}
	}

  

1 ACCEPTED SOLUTION

Did you check the source values? They must be 1:1.

Hmm, lets simplify this more.

if(action == 'update' && source.u_operational_status == 'Retired'){
		var grr = new GlideRecord('cmdb_rel_ci'); 
		grr.addQuery('parent.name', source.u_name);
		grr.addQuery('child.operational_status', '!=', '6');
		grr.query(); 
		gs.log('QUERY: current rows for ' + source.u_name + 'with non-retired childs is ' + grr.getRowCount());
		gs.log('QUERY: ' + source.u_name + ' ' + source.u_operational_status);
		if(grr.next()){
			gs.log('QUERY: Active child found! Ignore');
			ignore = true;
		}else{
			gs.log('QUERY: No active childs found! Do not ignore!');
			ignore = false;
		}
	}
}

 

If you run the transform and check the logs where message contains 'QUERY:' what does it log?

If nothing, then you need to check the values that are in your source table.

View solution in original post

24 REPLIES 24

rahulpandey
Kilo Sage

Hi,

grr.Query(); would be grr.query();

I ran below test script and it worked fine

var gr = new GlideRecord('cmdb_rel_ci');
gr.addQuery('child', '829e953a0ad3370200af63483498b1ea');
gr.query();
if(gr.next()){
gs.print(gr.child.operational_status.getDisplayValue());
}

Please mark my answer correct if it helped you.

 

The script is for transform, this is my requirement

but when i update the parent choice field to "retired" it should check for whether the child choice field value is in "Retired" status or not.

and if it finds as"retired" only then it can update the parent choice field with "retired" status otherwise it should skip or ignore

Yes,

I understand your requirement, however the syntax you are using is not correct.

grr.Query(); would be replaced by grr.query(); Try below

if(source.u_operational_status=="Retired")
	{
		var grr=new GlideRecord("cmdb_rel_ci");
		grr.addQuery("parent","source.u_operational_status");
		grr.query();
		while(grr.next());
		{
			
			if(grr.child.operational_status.getDisplayValue()!="Retired")
				{
					gs.log(grr.child.operational_status.getDisplayValue());
					ignore=true;
				}
		}
	}

I tried below script it didn't work

	
if(action=="update" && source.u_operational_status=="Retired")
	{
		var grr=new GlideRecord("cmdb_rel_ci");
		grr.addQuery("parent","source.u_operational_status");
		grr.query();
		while(grr.next())
		{
			gs.log(grr.child.operational_status.getDisplayValue());
			
			if(grr.child.operational_status.getDisplayValue()!="Retired")
				{
					
					ignore=true;
				}
		}
	}

Hi,

 

I found one more issue in your script

grr.addQuery("parent", "source.u_operational_status"); would be grr.addQuery("parent",source.u_operational_status);

First script to try :

if(action=="update" && source.u_operational_status=="Retired")
	{
		var grr=new GlideRecord("cmdb_rel_ci");
		grr.addQuery("parent",source.u_operational_status);
		grr.query();
		while(grr.next())
		{
			gs.log(grr.child.operational_status.getDisplayValue());
			
			if(grr.child.operational_status.getDisplayValue()!="Retired")
				{
					
					ignore=true;
				}
		}
	}

second step 2 try

if(action=="update" && source.u_operational_status=="Retired")
	{
		var grr=new GlideRecord("cmdb_rel_ci");
                grr.addEncodedQuery("parent="+source.u_operational_status+"^child.operational_status!=6");
		grr.query();
		while(grr.next())
		{
					
					ignore=true;
		}
	}