Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

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

This is interesting - thanks for sharing. This means that the discovery takes the model name from field which contains manufacturer, or there is something else going on which creates the model name as if it's the displayed model name. Good that you've found a workaround, which unfortunately is a common way to solve problems in ServiceNow platform.