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

Rob4
Giga Contributor

I know this is an old post but I came up with a solution for this with the following code: 

 

answer = (function transformEntry(source) {

var tab = new GlideRecord('sys_choice');
tab.addEncodedQuery('elementSTARTSWITHsys_class_name^labelLIKE' + source.u_class);
tab.query();
if(tab.next()){
return tab.value; // return the value to be put into the target field
}
})(source);

 

This has worked using the table label value and successfully changes the target dependent on that value and allowed an import of over 20k CI's to numerous tables in one import. 

 

Hope it helps someone else 🙂 

Community Alums
Not applicable

Thank you so much.