Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Looking for Recommendation on deleting CI Relationship

Nilanjan1
Mega Sage

Hello Experts. 

 

I am looking for recommendations, on deleting relationship when it there is a duplicate.

 

Use case: 

Created a onComplete script in a transform map to delete any duplicate relations in the relationship table.

The creation of type for  business Application relationship as child with type Consumes::Consumed by and Business Application as Parent is working through an Onafter script. 

 

I have created a script for deleting the relations, looking  for some inputs. it is required urgently.

 

 

(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
    var delCMDBRel = new GlideRecord('cmdb_rel_ci');
    delCMDBRel.addQuery('child', target.sys_id);
    delCMDBRel.addQuery('type', '41008aa6ef32010098d5925495c0fb94');
    delCMDBRel.query();
    if (delCMDBRel.getRowCount() > 0) {
        gs.addInfoMessage('CI relationships for ' + current.name + ' removed as it is no longer operational.');
    }
    while (ciRel.next()) {
        ciRel.deleteRecord();

    }
})(source, map, log, target);

 

0 REPLIES 0