[CMDB Model] Best practice to map the models while using the Import Sets/some type of integration to import the configuration items or assets


Description

There might be some situations where we need to map the models with while importing the configuration items and/or assets. Many times we may end up having duplicate models or empty values in the models. Or sometimes the models with unknown values.

This KB addressed how to map the models in the best way.

Release or Environment

All currently supported releases.

Cause

ServiceNow OOB models are built using the manufacturer, model, and model categories. Using this it uses the OOB script include "MakeAndModelJS" to create the models from the given manufacturer and model if the there is no existing model found with these inputs.

Duplicates can be created when using different logic to create the models.

Script Include Name: MakeAndModelJS - https://<instance name>.service-now.com/sys_script_include.do?sys_id=d7c58843ef72010098d5925495c0fb82

Resolution

Within your transform map make use of the below code and pass the proper parameters, to avoid duplicates, and it will take care of creating/finding the models and passing to them accordingly. 

- On the transform map click on "Run Scripts" and use the following line of code: 

runIt();

function runIt() {
setMakeAndModel();
}

function setMakeAndModel() {
var mm = MakeAndModelJS.fromNames("VAR_MANFACTURER", "VAR_MODEL_OF_DEVICE", "VAR_MODEL_CLASS");
target.model = mm.getModelNameSysID();
target.manufacturer = mm.getManufacturerSysID();
}

/* Replace the variable as below:
VAR_MANFACTURER: Manufacturer name
VAR_MODEL_OF_DEVICE: Device Model
VAR_MODEL_CLASS: Model type. Values are "hardware", "consumable", "software", "application", or the full name of the child table of cmdb_model, e.g. "cmdb_facility_product_model"
*/

Sample Transform Map with this change looks as below:

Additional Information

Refer  Create a transform map for more information about the transform map "Run Scripts".