Cleanup display_name in cmdb_hardware_product_model (No HAMP)

Tone1
Tera Expert

Hi,

i work on this problem for a couple of hours already but i still can not figure out a solid approach.

In cmdb_hardware_product_model we have Notebooks with Manufactuer HP and Name "HP Elite x360 830 13 inch G11 2-in-1 Notebook PC" this Creates a display_name "HP HP Elite x360 830 13 inch G11 2-in-1 Notebook PC". Our Procurement Guys dont want that HP HP. This Displayname gets created via OOTB BR "calculate display_name" on cmdb_model.

 

function _calculateDisplayName(){
    global.ModelUtils.calculateDisplayName(current);
}

_calculateDisplayName();

So i thought i'm super smart and do something like this:

 

function _calculateDisplayName() {
    var mfg = current.manufacturer.name + "";
    var modelName = current.name + "";

    if (mfg === "HP" && modelName.startsWith("HP ")) {
        var newName = modelName.substring(3).trim();
        if (newName !== modelName) {
            current.setValue('name', newName);
        }
    }

    global.ModelUtils.calculateDisplayName(current);
}

_calculateDisplayName();

What now happens, i get a stripped display name only with one "HP" as expected, but every Endpoint discovered gets its own hardware model, so suddenly i have a ton of duplicate HW Models each with one single asset/ci linked.

 

What is going on here? Did i miss some crucial step in the Asset/Ci creation?

1 ACCEPTED SOLUTION

Let's say i have "HP Elite x360 830" as Model Name, when i change it to "Elite x360 830" next time discovery gets data it will create a new hardware model with name "HP Elite x360 830" and link the asset from my changed Model entry to the new one created by discovery.

 

But i fixed it anyway myself by directly writing to display_name and skip OOTB function when HP HP is found.

 

function _calculateDisplayName() {
    var mfg = current.manufacturer.name + "";
    var modelName = current.name + "";

    if (mfg === "HP" && modelName.startsWith("HP ")) {
        var newName = modelName.substring(3).trim();
        current.setValue('display_name', "HP " + newName);
        return;
    }

    global.ModelUtils.calculateDisplayName(current);
}

_calculateDisplayName();

 

View solution in original post

5 REPLIES 5

Robert _ysakows
Tera Contributor

The display name is a concatenation of name and manufacturer. Remove the HP from the name and you won't get double HP in the display name.

thats exaclty what this is doing:

function _calculateDisplayName() {
    var mfg = current.manufacturer.name + "";
    var modelName = current.name + "";

    if (mfg === "HP" && modelName.startsWith("HP ")) {
        var newName = modelName.substring(3).trim();
        if (newName !== modelName) {
            current.setValue('name', newName);
        }
    }

    global.ModelUtils.calculateDisplayName(current);
}

_calculateDisplayName();

I am saying that you do not need to do any coding, just remove the manufacturer from the name of the model. I think you're trying to fix something what doesn't need to be fixed.

Let's say i have "HP Elite x360 830" as Model Name, when i change it to "Elite x360 830" next time discovery gets data it will create a new hardware model with name "HP Elite x360 830" and link the asset from my changed Model entry to the new one created by discovery.

 

But i fixed it anyway myself by directly writing to display_name and skip OOTB function when HP HP is found.

 

function _calculateDisplayName() {
    var mfg = current.manufacturer.name + "";
    var modelName = current.name + "";

    if (mfg === "HP" && modelName.startsWith("HP ")) {
        var newName = modelName.substring(3).trim();
        current.setValue('display_name', "HP " + newName);
        return;
    }

    global.ModelUtils.calculateDisplayName(current);
}

_calculateDisplayName();