Importing relationships- reference field value

joanct
Kilo Contributor

In an effort to get our CI data in SNOW configuration management , we   successfully identified critical CIs from old system and imported CIs into SNOW CMDB tables Now our team wants to import relationships to cmdb-rel-ci table from external source- CSV template extract.We have verified relationship type exists in cmdb-rel-type . But while trying to come up with a web service import set and transform map , we ran into challenges identifying whether its the tablename or the CI name that should be mapped in parent and child fields - so is it the CI name or CI's table name .if its the CI name - say VMserverC23 , is a script required for the parent and child   field on the web service transform map to check that specific CI data being imported exists in their original tables? what is reference field value on transform maps?

17 REPLIES 17

Bhavesh Jain1
Giga Guru

Your excel should contain 5 fields :


  1. Child Name
  2. Child Class
  3. Relationship Type
  4. Parent Name
  5. Parent Class


In your transform map, you will just map one field i.e. Relationship type


Rest of the mapping will be done in OnBefore transform script :



on Before transform script :



if (source.u_child_class != '' && source.u_child_name != '' && source.u_parent_name != '' && source.u_parent_class != '')


{


var gr= new GlideRecord('source.u_child_class');


gr.addQuery('name','source.u_child_name');


gr.query();


if (gr.next()) {


          target.child = gr.sys_id;


  }



var gre = new GlideRecord('source.u_parent_class');


gre.addQuery('name','source.u_parent_name');


gre.query();


if (gre.next()) {


          target.parent = gre.sys_id;


  }


}



Regards,


Bhavesh


IGate-logo.png


http://www.igate.com


Hey I just tried your script.



got errors so after a look:


  1. gr.addQuery('name','source.u_child_name');  

should be:


  1. gr.addQuery('name',source.u_child_name);  

Ishan4
Tera Contributor

Hi 

Did it work for you ?

Hi @Bhavesh Jain ,

I went through your this solution, I made the excel same way as you but it made relationship which has only populated relationship type and empty child and parent name and class.

I ran it from admin level.

 

My excel:

find_real_file.png

my services:

find_real_file.png

relationships:

find_real_file.png

 

script:

find_real_file.png