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

Joni5
Tera Expert

There are quite a few little issues with your script.

 

if(source.u_operational_status == '6'){ //Use value instead. 6 == Retired.
	var grr = new GlideRecord('cmdb_rel_ci'); 
		grr.addQuery('parent', source.sys_id); //parent is not the operational status. It's a sys_id of the source record.
		grr.query(); //query, not Query
	while(grr.next()){ //don't add ; here.

		if(grr.child.operational_status != '6') { //It's always better to compare the value instead of displayValue if possible.
			gs.log(grr.child.operational_status.getDisplayValue()); //Here you'll print the displayValue correctly into log. You might consider more info, such as
			//gs.log('current child operational status is: ' + grr.child.operational_status.getDisplayValue());
			ignore=true; //What exactly is this doing here? Is this script a part of a transform map or something?
		}
	}
}

rick48
Tera Contributor

yes the script is for transform map

 in the below code how the source.sys_id works ,since the source is from excel file.

 and my requirement is:

 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

grr.addQuery('parent', source.sys_id); //parent is not the operational status. It's a sys_id of the source record.
	

And in the below code:

how can i give the value in source.operational
_status since it is from excel 

if(source.u_operational_status == '6')

 

Well, I was expecting some other script at first, so that's why added the sys_id part.

On your original script you're basically saying "look for parent that equals 'Retired'", but the parent field is actually a sys_id, a reference to the application.

Are you actually trying to compare the source as a parent? Or are you trying to check that if the parents operational status is retired?

You could start by querying the cmdb_ci_appl table for your source record.

if(source.u_operational_status == '6'){ 
	var gr = new GlideRecord('cmdb_ci_appl');
	gr.addQuery('name', source.name);
//above I'm expecting the excel source to have a matching application name.
	gr.query();
	while(gr.next()){
	
	var grr = new GlideRecord('cmdb_rel_ci'); 
		grr.addQuery('parent', gr.sys_id); 
		grr.query(); 
	while(grr.next()){ 

		if(grr.child.operational_status != '6') {
			gs.log(grr.child.operational_status.getDisplayValue());
			ignore=true;
		}
	}
}
}

 

But if you want to get all parents with operational status 'retired, then you need to do this:

 

if(source.u_operational_status == '6'){ //Use value instead. 6 == Retired.
	
	var grr = new GlideRecord('cmdb_rel_ci'); 
		grr.addQuery('parent.operational_status', 6); 
		grr.query(); 
	while(grr.next()){ 

		if(grr.child.operational_status != '6') {
			gs.log(grr.child.operational_status.getDisplayValue());
			ignore=true;
		}
	}
}
}

rick48
Tera Contributor

when the child doesn't have operational status has retired its updating parent record when i give operational status as retired in the excel which i used in the data source

var gr=new GlideRecord('cmdb_ci_appl');
	gr.addQuery('name', source.name);
	gr.query();
	while(gr.next()){
	if(action=="update" && source.u_operational_status == 'Retired')
{
	var grr = new GlideRecord('cmdb_rel_ci'); 
		grr.addQuery('parent', gr.sys_id); 
		grr.query(); 
	while(grr.next()){ 

		if(grr.child.operational_status != '6') {
			gs.log(grr.child.operational_status.getDisplayValue());
			ignore=true;
		}
	}
}
}