If parent CI is retired, then child CI CI needs to be retired

Hanumant Madan1
Kilo Guru

Hello All,

I have below requirements:

When a discovered CI is Retired all components that were discovered on the CI should automatically be retired with the CI is Retired.

Any way to develop something that will look at all CIs and if parent CI is anything other than Install Status "Installed" then the child CIs are updated to Retired or to match the status of the parent CI.

Any help will be appreciated.

 

Regards,

Hanumant

12 REPLIES 12

Tony Chatfield1
Kilo Patron

Hi, if there is no other requirement\dependency then a simple 'after' BR could be all you need

trigger conditions;
current.operational_status.changes() && current.operational_status == 6 //retired.

script;

//query for child relationships
var gr = new GlideRecord('cmdb_rel_ci');
gr.addQuery('parent', current.sys_id);
gr.query();

while(gr.next()) {
//for each child found look up the record and update the status
	var myCI = new GlideRecord('cmdb_ci');
	if(myCI.get(gr.child.sys_id)) {
		myCI.operational_status = 6;
//Or you could make this child state dynamic by ommiting state 6 from the trigger conditions and referencing the current CI's status
//myCI.operational_status = current.operational_status;
		myCI.update();
	}
}

Hi Tony,

Thank you so much for help.

As of now no other requirements, but let me check if the point mentioned by @Rahul Priyadarshy about removing the CI_relations...I am not exactly sure what will be the benefit of that.

Do you suggest BR or scheduled job for this for long term.

But for now we are only asked to change statuses of the child CIs.

 

Regards,

Hanumant

Random question on this - will changing the child CI from the BR, trigger the same BR to be run for the child CI? This would need to happen else the child CI may leave orphans, right? If needed it would be simple enough to add some loops and recycle until we find CIs with no children, but it’s definitely extra code. Just curious if it is necessary.

 

The above BR  should run on "cmdb_ci_rel" table?

 

will that make child CI status to retired as expected?

 

Regards,

Hanumant