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

Ah, I see. And I expect that you have a source name field that's a coalescence field for the name in application table, correct?

 

if(action == 'update' && source.u_operational_status == 'Retired'){
	var gr = new GlideRecord('cmdb_ci_appl');
	gr.addQuery('name', source.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 = false;
			}else{
				ignore = true;
			}
		}
	}
}

 

Here the whole process is:
1. Check if update and source operation status is 'Retired';

2. Find a matching Application.

3. Find a relation where the parent is the application.

4. Check if the childs operational status is 'Retired'.

5. If it's not then ignore this update as parent can't be 'Retired' if child is not.

rick48
Tera Contributor

even this script didn't work its still updating when i give operationl status=Retired in (Excel) when the childs operational status = "retired"

below is my screen shots

 

find_real_file.png

childs operational status:

find_real_file.png

Excel(source)

find_real_file.png

Could you check the source table and what is the value (name) of the Operational Status and name field in there?

/*if the source field is u_operational_status and the source name is u_name, then this should be OK.
*/

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()){
		var grr = new GlideRecord('cmdb_rel_ci'); 
		grr.addQuery('parent', gr.sys_id);
		grr.addQuery('child.operational_status', '!=', '6');
		grr.query(); 
		if(grr.next()){
			ignore = true;
		}else{
			ignore = false;
		}
	}
}

I originally missed u_name in the gr query.

Also the while loop could change the ignore to be wrong in your case as it looped through all the childs.

I modified this to also query on the relationship table that operational status is not Retired.

If something is found, then the update is ignored as there's a child that isn't retired. Otherwise it's Ok to retire the parent.

rick48
Tera Contributor

still its updating the parent operational status to retired even when the childs operational status is not in Retired

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.