Automatic relationship creation

snowlover1
Kilo Contributor

I have created a relationship between   parent class and child class in Suggested relation ship table. Based on this, when i import   parent CI

and child CI to cmdb_ci tables   ,   relation ships(in cmdb_rel_ci)   will be created automatically? or do we need to create manually?  

Thanks

Mike

8 REPLIES 8

We ended using an onAfter transform script to automatically create relationships from a file import in combination with the suggestions in the link I posted above on 12/15/2015. Hope this helps.


Thanks,


Sherry


snowlover1
Kilo Contributor

Hi ,



I am trying   to add relationship where   I import the child. I i knew already the parent CI and   relation type   to be added.



Record is adding in the cmdb_rel_ci   with empty paren CI and Child CI.



I added code in   complee() transform script. Can you pl tell   me what is the error in the following script



var grRel = new GlideRecord('cmdb_rel_ci');


grRel.parent.cmdb_ci.name ="X_ci";


grRel.child.cmdb_ci.name = "Y_ci";


grRel.type = "Connects to::Connected by";


inc.insertWithReferences();




Thanks


Mike


snowlover,


Try using the sys_id of the relationship type:



grRel.type = ("sys_id");



Also, you want to do the insert on the relationship table, so instead of inc.insertWithReferences(); use:


grRel.insertWithReferences();


vikashrandstad
Tera Contributor

You need to establish the relationships in cmdb_rel_ci explicitly

 

In ServiceNow, when you define relationships between parent and child classes in the Suggested Relationships table, the platform provides guidance on which relationships can exist. However, suggested relationships do not automatically create actual relationships in the cmdb_rel_ci table when you import Configuration Items (CIs) into the cmdb_ci table.