Name - Configuration Item update

kalpeshjath
Tera Contributor

Hi,

 I have created a bulk upload template for updating Asset records. In the bulk upload template, I have one field as “Name” through which I am updating "Configuration Item" field on alm_hardware table and the "Name"  is getting updated on “cmdb_ci” table. The issue which I am facing is if the Configuration Item is same then it is updating the records correctly. Only if the Configuration Item is different then instead of updating the record it is creating a new CI on cmdb table and that to also under wrong class as Configuration Item.

Please can some one help me on the this and how can I resolve this. Serial number is the “Coalesce” field.

kalpeshjath_0-1745325020459.png

 

 

Onbefore

(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {

    if (source.u_name) {

        gs.log("Looking for CI with name: " + source.u_name, "Test Hardware Upload Transform");

        var ci = new GlideRecord('cmdb_ci');

        ci.addQuery('name', source.u_name);

        ci.query();

        if (ci.next()) {

            gs.log("Found CI with sys_id: " + ci.sys_id, "Test Hardware Upload Transform");

            target.ci = ci.sys_id;

        } else {

            gs.log("CI with name " + source.u_name + " not found.", "Test Hardware Upload Transform");

        }

    }

})(source, map, log, target);

 

onAfter

(function runTransformScript(source, map, log, target) {

    if (source.u_name && target.ci) {

        gs.log("Updating CI with sys_id: " + target.ci + " to name: " + source.u_name, "Test Hardware Upload Transform");

        var ci = new GlideRecord('cmdb_ci');

        if (ci.get(target.ci)) {

            ci.name = source.u_name;

            ci.update();

            gs.log("CI updated successfully.", "Test Hardware Upload Transform");

        } else {

            gs.log("CI with sys_id " + target.ci + " not found.", "Test Hardware Upload Transform");

        }

    }

})(source, map, log, target);

2 REPLIES 2

Ankur Bawiskar
Tera Patron
Tera Patron

@kalpeshjath 

your image is not clear. share a clear image

you are doing coalesce on Serial Number field so if it finds then it will update

If it doesn't find it will insert and it won't have any dependency with name field

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Yes Coalesce is on Serial Number but it is creating a new CI always whether Serial Number is available or not.