I need to be able to load CI Relationships for CIs with duplicate CI Names
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2015 06:25 PM
Even though the sysid of the parent and child CIs does exist on the CI Relationship form (I can see these when I pull back an xml extract) I am not able to map these in the transform map to load. This is an issue because the CI Name is not unique on many CIs. Does anyone know how I can add the sys id for the parent and child ci to my transform map so I can load relationships to cmdb_rel_ci for assets that have duplicate CI names?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2016 12:52 PM
In case others are still looking for a solution, basically before the import starts we're going to find the sys ids for the CIs on the file so that when you create the relationship it grabs the correct CI in the correct class. Here you go:
/**
Example code for finding correct CIs for relationships when CIs in different classes have the same name
when importing relationships on a transform map
Run script: is checked
Place this script in the Script field on the Table Transform Map
**/
getCisForRel();
function getCisForRel(){
//grab the parent from the current file
var parentOnFile = source.u_parent;
var app = new GlideRecord("cmdb_ci_appl");
//grab the child from the current file
var childOnFile = source.u_child;
var phy = new GlideRecord("cmdb_ci_server_hardware");
var relParent = "";
var relChild = "";
//find the parent and grab the sys_id
app.addQuery("name", "=", parentOnFile);
app.setLimit(1);
app.query();
while (app.next()){
if(!app.name.nil())
relParent = app.sys_id;
}
//find the child and grab the sys_id
phy.addQuery("name", "=", childOnFile);
phy.setLimit(1);
phy.query();
while (phy.next()){
if(!phy.name.nil())
relChild = phy.sys_id;
}
//set the target fields to the sys_ids we grabbed
target.parent = relParent;
target.child = relChild;
}