Remove CI Relationship in IH ETL

pbels1
Tera Contributor

We are getting a delta file from on of internal partner and need to remove CI Relationship is there a way in Integration Hub ETL to remove CI Relationships?

2 REPLIES 2

Arby
Tera Contributor

This is a real problem for us too and wasn't able to find a solution yet.

Guus Bouts1
Tera Contributor

Hi,

Ran into your post while experiencing a similar demand; an existing IntegrationHub ETL transform map was only adding new relationships, not even overwriting existing ones.

From what I could determine this seems the way it is, only inserts as you stated.
However, in case you are still searching for a potential work-around, please consider the following I've been able to successfully setup. Our use case was a server import job would have to be updated accordingly to the correct service offering. Before our action it would simply keep adding relationships, never updating.

So to resolve this I've added an After Transform script on the CMDB Integration Studio Application Data Source (alternatively: System Import Sets > Robust Import Set Transformers > Select the one you need to edit and open the Transformer Definition). Mark the "Execute After Script" en provide a script which does what you need, our example below:

(function(ireOutput, ireInput, runId) {

    for (var i = 0; i < ireOutput.length; i++) {

        var output = ireOutput[i];
        var items = output.items;

        for (var j = 0; j < items.length; j++) {

            // check if relations exist for this server we just added
            if (items[j].className == 'cmdb_ci_server') {

                var serverId = items[j].sysId;

                var relationGR = new GlideRecord('cmdb_rel_ci');
                relationGR.addQuery('child', serverId);
                relationGR.orderBy('sys_created_on');
                relationGR.query();

                var rowCount = relationGR.getRowCount();

                // If we found more than one record, multiple relationships exist; delete (all) but the oldest, but leave the last one
                while (rowCount != 1 && relationGR.hasNext()) {
                    if (relationGR.next())
                        relationGR.deleteRecord();

                    rowCount -= 1;
                }
            }
        }
    }
})(ireOutput, ireInput, runId);

Hope this helps you out still.

Regards,
Guus