How do I import a set of Locations from CSV and still maintain Parent Reference?

snow_hard252
Kilo Contributor

Hi,

How do I import a set of Locations from CSV and still maintain Parent Reference?

I have Locations dumped in CSV and have Fields REGION, COUNTRY, STATE.

Just as in cmn_location table, I would like to have this data of locations imported, to have a Hierarchical Display in the Look up List as for Location field in cmdb_ci.

location_hierarchy.PNG

Could some body help?

Thanks

Hardy

1 ACCEPTED SOLUTION

sumukh
Kilo Expert

Hi Hardy,



This can be easily done through transform maps in one go. You'll need couple of things in the data:



  1. A unique identifier (not sys_id) like a location code. Doing import solely based on plain text is not recommended and more error prone. We will use this as a coalesce field for this transform
  2. Hierarchy mapped in the data i.e. Parent-Child relationship (As mentioned by Abhiram)


Now while creating the transform map do fieldmaps like this:



Source fieldTarget fieldCoalesce
u_namenamefalse
u_parentparentfalse
u_loc_codeu_loc_codetrue


You don't have to write even a single line of code.



Hope this helps.



Thanks.


View solution in original post

5 REPLIES 5

adiddigi
Tera Guru

The CSV should include another column called "parent" which gives the parent location for a location.


This is two fold. On location table you have something called "parent". This table is a self referencing table meaning a Location will have a location as it's parent.



The transformation need to be done in two steps:



- First you will have to only insert the parent locations ( Meaning Parent = Null)


- Second you will have to process only children, and when you do so write a Transform Script to set the parent( created from step 1)


If you give me some sample data, we can work through it.


HI Abhiram,



Appreciate your response.


To your point CSV should include another column parent, I agree . But I have more than 2500 Physical Locations and Since I have 3 Tier Hierarchy REGION, COUNTRY, STATE, do you mean I need to columnize parent ; parent.parent ; parent,parent.parent ?



Thanks


Hardy


sumukh
Kilo Expert

Hi Hardy,



This can be easily done through transform maps in one go. You'll need couple of things in the data:



  1. A unique identifier (not sys_id) like a location code. Doing import solely based on plain text is not recommended and more error prone. We will use this as a coalesce field for this transform
  2. Hierarchy mapped in the data i.e. Parent-Child relationship (As mentioned by Abhiram)


Now while creating the transform map do fieldmaps like this:



Source fieldTarget fieldCoalesce
u_namenamefalse
u_parentparentfalse
u_loc_codeu_loc_codetrue


You don't have to write even a single line of code.



Hope this helps.



Thanks.


I've done this exact same process and just as sumukh stated, the location code is "key".   The transform map runs and all data is imported in a single step.