Can we have same CI names belonging to 2 different classes in CMDB? If yes, then how do we perform relationship data load into system?

iadityas
Mega Expert

Can we have same CI names belonging to 2 different classes in CMDB? If yes, then how do we perform relationship data load into system?

18 REPLIES 18

acirovic1
Giga Expert

You can specify in the import file the CI class (sys_class_name) explicitly and then use a script to coalesce the correct CI.


Hi Aleksander,



I am still thinking, how to do it?


Ideally, cmdb_rel_ci table requires Parent/Child/Type to create a relationship correctly. Since I have same value in both Parent and Child though they belong to different classes the mapping with destination table is not straight forward. Not getting sys_class_name on destination - on UI it is appearing from Reference field. Still unable to understand why is this not working from UI.



Regards,


Aditya


Maybe you're selecting the same object or there are already relationships that together with the newly created one cause a recursive loop.


dhathrianoop
Giga Expert

var gr=new GlideRecord('x_42426_automation_automation_rules');


gr.addQuery('automation_category','calculate_relationship');


gr.orderBy('order');


gr.query();


  while(gr.next())


  {


  var attribute=gr.getValue('target_attribute');


  var val=gr.target_value;


  var query = gr.getValue('query_string');


  var match=GlideFilter.checkRecord(current,query);



    if (match)


    {


    var childT=current.sys_id;


    var manages='bf83653c0ab30150761028c73a4de0f4';


    setRelationshipValues(val, childT, manages);


    }


}



function setRelationshipValues(parent, child, relationshipType) {


    // gs.addInfoMessage(parent);


    // gs.addInfoMessage(child);


    // gs.addInfoMessage(relationshipType);



      if (parent == child)


          return;



    var rel_ci = new GlideRecord("cmdb_rel_ci");


    rel_ci.initialize();


    rel_ci.parent.setDisplayValue(parent);


    rel_ci.child = child;  


    rel_ci.type = relationshipType;


    rel_ci.insert();


}