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

 i tried both the script still the parent(cmdb_ci_appl) is getting updated when the child is not "Retired"

Jidesh,

what is source.u_operational_status  data type ? is it reference or string because, it is confusing

if(action=="update" && source.u_operational_status=="Retired")

Above you are evaluating against =="Reitred"

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

Here you are trying to evaluate against a reference field.

no its choice field

Hi Please try below

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

i tired the above script it didnt work..

i need to get the child of only the application which i have updated,not the entire cmdb_rel_ci

if suppose i update the application to "retired" it should check only that applications child records not the entire cmdb_rel_ci 

i tired with below script it checks for every child records..

(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {

if(action == 'update' && source.u_operational_status == 'Retired'){
	var gr = new GlideRecord('cmdb_ci_appl');
	gr.addQuery('name', source.u_name);
	gr.query();
	while(gr.next()){
		gs.log("entry");
		var grr = new GlideRecord('cmdb_rel_ci'); 
		grr.addQuery('parent', gr.sys_id);
		grr.addQuery('parent.name',source.u_name);
		grr.addQuery('child.operational_status', '!=', '6');
		grr.query(); 
		if(grr.next()){
			gs.log("false");
			ignore = true;
		}else{
			gs.log("before true");
			ignore = false;
		}
	}
}
})(source, map, log, target);