Creating dynamic relationship (cmdb_rel_ci)

snowlover1
Kilo Contributor

Hi All,

I am trying to create relationship in (cmdb_rel_ci)   when import the child CIs. I   Knew the parent CIs for those child ci .

I am using the type as Connects to::Connected by". It is also available in suggested relationships

I am using the following code in the oncomplete() transform map events.. it is creating relationship ..but with empty Parentid and Child CIs.

var grRel = new GlideRecord('cmdb_rel_ci');

grRel.parent.cmdb_ci.name = 'x.ci';     // Hard coded

grRel.child.cmdb_ci.name = source.name;

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

inc.insertWithReferences();

Thanks

Mike

3 REPLIES 3

Deepak Ingale1
Mega Sage

Hi Mike,



I would try to do this with OnBefore transform map script



Also, at line number 3, your assigning import set table field value to cmdb_rel_ci table. Normally, your import set field values are prefixed with u_ since those are custom created tables.So kindly try to change this line as well



  • grRel.child.cmdb_ci.name = source.u_name;

She Sull
Giga Guru

You want to use the sys_id of the relationship type record:



grRel.type = ("sys_id");



Also, try using an onAfter transform script.


mrswann
Kilo Guru

I have achieved a similar thing and posted my script to that question - as I need to understand how to coalesce these fields!



transform coalesce via script (cmdb_rel_ci)


I have achieved with a OnBefore... and then I am doing a GlideRecord query to get the sys_id of the parent & child CIs




(I say achieved, I ran it on a test record and babysat it through the processing... now I am running a full discovered relationship map CSV its not quite working! but I think my post may help...)