How to update sys_class_name via Transform Map script?

Community Alums
Not applicable

I am trying to import some records into cmdb_ci table. My excel sheet does have a column Class=Computer. But in transform map, when I do an Auto mapping.. I could not find the sys_class_name field in my target table.   So, in the run script block, I wrote the following assuming it will update the Class along with other columns.

target.sys_class_name = source.u_class; //Did not work -------------need help

To be more accurate, I updated my excel file to have values 'cmdb_ci_computer' for Class column.

But, it does not take this value. It shows the Class as 'Configuration Item'

Need help please.

1 ACCEPTED SOLUTION

drjohnchun
Tera Guru

Unless someone has a clever solution, I always import CIs class-by-class, your issue being one of the reasons; sys_class_name is set by the system automatically based on the target table you pick.



Hope this helps.



Please feel free to connect, follow, mark helpful / answer, like, endorse.


John Chun, PhD PMP see John's LinkedIn profile

visit snowaid


ServiceNow Advocate

Winner of November 2016 Members' Choice Award


View solution in original post

6 REPLIES 6

drjohnchun
Tera Guru

Unless someone has a clever solution, I always import CIs class-by-class, your issue being one of the reasons; sys_class_name is set by the system automatically based on the target table you pick.



Hope this helps.



Please feel free to connect, follow, mark helpful / answer, like, endorse.


John Chun, PhD PMP see John's LinkedIn profile

visit snowaid


ServiceNow Advocate

Winner of November 2016 Members' Choice Award


andy_trayler
Giga Contributor

It is possible to use the transform map to set the class type. The transform map in my example has the target table set to cmdb_ci_server and the script associated with the transform map uses   columns defined in the data source (in this example called product and operating_system) to select the most appropriate target class.


The only restriction that I found when performing this type of "upgrade" class operation is that the field mapping will only support the "BASE" class attributes (in my case cmdb_ci_server attributes) and not those in the derived classes.



---SNIP---



var devType = source.u_product.toString().toUpperCase();


var operating_system = source.u_operating_system.toString().toUpperCase();



if (devType == "WINDOWS SERVER"){ target.sys_class_name="cmdb_ci_win_server"; }


else if (devType == "UNIX"){


  if (operating_system == "HP-UX"){ target.sys_class_name="cmdb_ci_hpux_server"; }


  else if (operating_system.match(/SUNOS/i) != null){ target.sys_class_name="cmdb_ci_solaris_server"; }


  else if (operating_system.match(/AIX/i) != null){ target.sys_class_name="cmdb_ci_aix_server"; }


  else if (operating_system.match(/LINUX/i) != null){ target.sys_class_name="cmdb_ci_linux_server"; }


  else {target.sys_class_name="cmdb_ci_unix_server"} //just unix


}


else if (devType.match(/NETWARE/i) != null){ target.sys_class_name="cmdb_ci_netware_server"; }


else if (devType.match(/DARWIN/i) != null){ target.sys_class_name="cmdb_ci_osx_server"; }



Andy Trayler


target.sys_class_name="cmdb_ci_hpux_server"; worked for me. 

Jason Nichols
ServiceNow Employee
ServiceNow Employee

I performed a simple import, containing two server classes (Windows and Linux) into the cmdb_ci_server table. The values in my import file were "Windows Server" and "Linux Server" and these had to be changed upon import to "cmdb_ci_win_server" and "cmdb_ci_linux_server", respectively, as these are the actual values for the Class field in the table.

find_real_file.png

 

The short script to transform the values in the import file:

find_real_file.png