Transform map script inserts a new record instead of updating the queried record

Arathi B Raj
Mega Contributor

Please find the below code- where we compare the manufacturer attribute from the data source table to the cmdb_ci table- if it finds a matching manufacturer record, the serial no attribute( cmdb_ci table) of the same record should get populated with the serial no from the data source table.

Issue- Instead of populating the serial no for the matching record, it creates a new record.

find_real_file.png

var gr= new GlideRecord("cmdb_ci");
gr.addQuery('manufacturer',source.u_manufacturer);
gr.query();

while ((gr.next()));
{
if (target.u_serial_number== source.u_serial_number);
gr.setValue(target.u_serial_number, source.u_serial_number);
gr.update();
}

3 REPLIES 3

Nayan Mahato
Tera Guru

Hi Arathi B Raj,

If your target table is "cmdb_ci" only then no need to use gr. update. Simple use the below script and should work. You could also use "Source script" as a field map as well. Thanks.

 

var gr= new GlideRecord("cmdb_ci");
gr.addQuery('manufacturer',source.u_manufacturer);
gr.query();

if((gr.next()));
{
if (target.u_serial_number== source.u_serial_number);
target.u_serial_number=source.u_serial_number;

}

 

Regards,

Nayan

 

Hi Nayan

Thanks for the help!

I tried the above script as well but still it is creating new records instead of updating.

Hi Arathi,

 

What is your target table in the transform map?

And also make sure that in the filed mapping you have made "u_serial_number" as coalesce true.

 

Regards,

Nayan