Remove Asset-CI Relationship

kristenankeny
Tera Guru

Due to some mistakes in implementing assets and CIs, we have some CI-Asset pairings that need to be broken because the CI is not an asset. We're hoping to not lose the historical information on what tickets were raised for different CIs, so the goal is to remove the relationship and then later clean up the asset records to remove anything that shouldn't be there. I have a fix script, but it's not doing the trick. I'm just testing with a single record at the moment. Has anyone successfully done this before and could point me to why this script isn't working?

If it's helpful at all, when I have the asset record open while running the script I can see the "changed" icon appear next to the configuration item field, but upon refresh the link is still there.

var cleanupTbl = 'cmdb_ci_storage_server';
var cT = new GlideRecord('cmdb_ci_storage_server');
cT.addQuery('sys_id','a4d76ca74fd0f2c07cf47bcd0210c749');
cT.setLimit(1);
cT.query();
while(cT.next()){
    var fixAsset = new GlideRecord('alm_hardware');
    fixAsset.addQuery('ci',cT.sys_id);
    fixAsset.query();
    while(fixAsset.next()){
        fixAsset.setValue('ci','');
        //asset.ci = '';
        fixAsset.update();
    }
    cT.asset = '';
    cT.model_id = '';
    cT.model_number = '';
    cT.serial_number = '';
    cT.update();  
}

4 REPLIES 4

Shane J
Tera Guru

Why are you using setValue in one case and then doing = '' in the other?

That's the the result of me adjusting back and forth from setValue and = '' to see if it made a difference to it working. Different iterations of the script had them all as setValue and another with them all as = ''.

OK, did you dig through existing BR's to see if they are repopulating the field?

kristenankeny
Tera Guru

In the end, I was able to convince the people that owned the data that our best course of action was to completely delete all their records and recreate from scratch.