How to get correct CI Class for imported Assets?

braddiamond
Giga Expert

I am importing asset data through a transform map/import set, and am setting my model category (Computer for instance), but yet, the CI that is created is not being set to the Computer class.   It keeps creating a CI with the 'Configuration Item' class.

Any suggestions on what I should be including in my transform to get the CI to create properly?   When we manually create a Computer Asset, the Ci is created correctly, so the Model Category is setup properly.

Thanks!

Brad

1 ACCEPTED SOLUTION

Ben,



I wanted to give you an update - we found the issue.   In one of my field mappings, I was asked to populate the CI name based on some other criteria.   Because we did this, the CI was then created before the AssetAndCISyncronizer could run - by then, there was already a blank shell of a CI in the CMDB.



We removed this mapping - and voila!   The CI creates the way it should.



Thanks all for the responses.


View solution in original post

10 REPLIES 10

Community Alums
Not applicable

Hi Bradley,



Thanks for the tag. What are you importing as the value for your Model category on the Assets? This is what determines the type of CI to create.


Also, how are you handling Models on the import? Have you done something to ensure the Model exists before you create the Asset?



Thanks,


Ben


Thanks for the quick reply Ben!



Here is the script I'm using for the Model Category field mapping - I'm checking for a valid model (which we have pre-populated in a previous import), and then returning the model category if the model exists.   Should I be returning the sys_id instead?



answer = (function transformEntry(source) {


  var objModels = new GlideRecord('cmdb_model');


  objModels.addQuery('name', source.u_model);


  objModels.query();


  if (objModels.next()){


  return objModels.cmdb_model_category;


  }



})(source);


Community Alums
Not applicable

Hi Bradley,



Part of the problem with this is that a Model could have more than one associated Model category. So you might run into an issue with that. Have you tried writing anything to the system log to validate what is being returned is what you expect? Do the Models properly have Model categories identified?



Not to get side tracked and while I enjoy the power of JavaScript and what you can do with it on the platform, have you considered any non-scripting approaches?


For example, I usually approach the Models as you describe: pre-populate it with an earlier import. If all your data is in a single spreadsheet, you can even do this with another transform map that runs first on the same transform. I do this with Models because there are a number of fields I want to populate when I create the Models and because it can be fairly common to need to bring in new Models (depending on your Model management strategy.



Model categories, however, should be pretty well defined in the environment. Rather than trying to import or pull them dynamically, I usually just include the category I want to use for the Asset in the spreadsheet and import that. All the values I use in the spreadsheet should match existing Model categories, but I use the Choice action on the field to reject the record if it does not match, just in case. This means for your asset import, you would have a category field that maps to the Model category for the asset.



Ben


Ben,



I wanted to give you an update - we found the issue.   In one of my field mappings, I was asked to populate the CI name based on some other criteria.   Because we did this, the CI was then created before the AssetAndCISyncronizer could run - by then, there was already a blank shell of a CI in the CMDB.



We removed this mapping - and voila!   The CI creates the way it should.



Thanks all for the responses.


Thank you. I made the same mistake, this helped me a lot. After deleting the mapping, all is fine now. thanks for updating this! 🙂