Transform Map - CMDB Model - transformEntry

PHOTO EMBED

Mon Mar 18 2024 04:19:18 GMT+0000 (Coordinated Universal Time)

Saved by @kieoon #transformmap #transformentry

answer = (function transformEntry(source) {

    // Handle Model column with or without manufacturer, as long as the model name is unique in the [cmdb_model] table
    if (source.u_model.toString() !== '') {
		// Perfect: Model field contains the Model's display name
        var encQ = 'display_name=' + source.u_model.toString().trim();
		// Almost perfect: Concatenate the import table's manufacturer field if supplied to recreate the Model display name
		if (source.u_manufacturer.toString() !== '') encQ += '^ORdisplay_name=' + source.u_manufacturer.toString().trim() + ' ' + source.u_model.toString().trim();
		// Try to find a unique name on the Model table without a manufacturer
        encQ += '^ORname=' + source.u_model.toString().trim();

        var grModel = new GlideRecord('cmdb_model');
        grModel.addEncodedQuery(encQ);
        grModel.query();

        // Unique models only
        if (grModel.getRowCount() == 1) {
            grModel.next();
            return grModel.getDisplayValue();
        } else {
            gs.info("EAM Tactical Asset Transform Map: Unable to create Asset. Found more than 1 Model by the name of: " + source.u_model.toString());
        }
    }

})(source);
content_copyCOPY