Remove CI Relationships
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-29-2014 05:48 PM
My goal is to be able to "retire or decommission" a CI. Using the Server Class, I will use a Windows Server as an example.
In our environment, we can retire a server running Windows, then bring it back online as a Linux machine. For reporting purposes and requirements by our CMDB team, we will need to keep the old CI record and the new CI discovered record. The current server will be active with all details and the previous server is set to inactive and numerous fields are cleared.
I have the code for removing all fields and linking the old CI to the new CI, but I am looking for assistance with the removing relationships part. What is the best way to purge the relationships on a CI?
Example: The retired Windows server was running an instance of MSSQL. This machine is clearly no longer running the database. So while we want to keep the records about the software that was installed, disk drives, serial numbers etc... , I want to remove the relationship(s) that would only be accurate if the machine is still "active". What is the best way to handle this?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-30-2014 02:29 AM
Hi Jeremy,
You can create an active field on the cmdb_rel_ci table, the default value should be false. Once the CI retires, all the dependent relationships can be deactivated. You can have a query business rule which will filter the data accordingly to the active field.
Please let me know if this helps.
Thanks and regards,
Pratik Limbore

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-30-2014 05:26 AM
We use an 'after' update business rule in the CMDB/Asset management turnkey to automatically do this. It's one of a ton of useful features to manage these areas in the system. Feel free to contact me directly if you'd like more information. Here's the script from the business rule we use.
removeCIRels();
function removeCIRels(){
//Query the CI relationship table
var ciRel = new GlideRecord('cmdb_rel_ci');
ciRel.addQuery('child', current.sys_id).addOrCondition('parent', current.sys_id);
ciRel.query();
if(ciRel.getRowCount() > 0){
gs.addInfoMessage('CI relationships for ' + current.name + ' removed as it is no longer operational.' );
}
while(ciRel.next()){
ciRel.deleteRecord();
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-30-2014 03:28 PM
This works perfect! Thank you Mark 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-30-2014 03:29 PM
Where is the choose correct answer? Did I post this in the wrong place?