Write to different tables in transform map

tpoeckes
Giga Guru

I have one import set table defined that will hold data for three (3) different classes: 1.) cmdb_ci_ip_firewall,   2) cmdb_ci_ip_router,   3.) cmdb_ci_ip_switch.   In the import table, there is a class field that tells me what class the data needs to written to.   The three classes will have two (2) attributes: 1.) sys_id and 2.) os_version.   In the transform map, do I need to defined three (3) different maps, or is there a way that I could scripted it to updated the three classes depending on what class record I'm processing?

1 ACCEPTED SOLUTION

Michael Fry1
Kilo Patron

You can definitely script it. If you look at the out of the box Computer one, it gives you idea how to do it:


if (source.operating_system == "AIX" ||


      source.operating_system == "HP/UX" )


  target.sys_class_name = "cmdb_ci_unix_server";



if (source.operating_system == "Windows 2000 Server")


  target.sys_class_name = "cmdb_ci_win_server";



basically it's


if (source.field-name-from-spreadsheet == "value here") < - - - from spreadsheet, column heading could be Class and choices are Firewall, IP Router, etc


  target.sys_class_name = "cmdb_ci_win_server"; < - -   this is table to insert into.


View solution in original post

5 REPLIES 5

Michael Fry1
Kilo Patron

You can definitely script it. If you look at the out of the box Computer one, it gives you idea how to do it:


if (source.operating_system == "AIX" ||


      source.operating_system == "HP/UX" )


  target.sys_class_name = "cmdb_ci_unix_server";



if (source.operating_system == "Windows 2000 Server")


  target.sys_class_name = "cmdb_ci_win_server";



basically it's


if (source.field-name-from-spreadsheet == "value here") < - - - from spreadsheet, column heading could be Class and choices are Firewall, IP Router, etc


  target.sys_class_name = "cmdb_ci_win_server"; < - -   this is table to insert into.


mrswann
Kilo Guru

are you just writing directly to cmdb_ci and then setting the class as a value?



I might have been doing this the wrong way round then, using a transform map for each target table and then using ignore against those rows which don't match the OS Type check, as an example...



I was conscious this would be fairly intensive as its effectively processing everything each time - so the above usage looks more efficient; where can I find the example you reference please?


got this working thank you




one thing I have found necessary here, and I am still testing... use the field map to apply base fields including those to coalesce; and then use the transform script to apply those which only exist within the sub-class tables in accordance with the class mapping identified.



I don't fully understand how this is working, as I expected the extended tables to exist in isolation but every sub class CI is still present on the base cmdb_ci table... but with extra fields :S


Once you start using the scripting, the script will grow and grow. Glad it's working.