How to change a target table in transform map

vikkyvivek
Tera Contributor

Hi. I have a requirement with the transform map. 

How to change the target table according to the field value?

Values are created from excel to cmdb_model table. If the asset class is "Software", the target table should be cmdb_software_product_model and if the asset class is "Hardware", the target table should be cmdb_hardware_product_model. And the Field mappings which I have created should goes to target table. I have tried 'Run script' in transform map.

 

(function transformRow(source, target, map, log, isUpdate) {

if (source.u_asset_class == "Software") {
target.setTableName("cmdb_software_product_model");
} else if (source.u_asset_class == "Hardware") {
target.setTableName("cmdb_hardware_product_model");
}

})(source, target, map, log, action === "update");

2 REPLIES 2

Jean Ferreira
Giga Guru

Try to set the Target table as Configuration Item (cmdb_ci). 
Then create a field map setting the class name attribute. Then use your condition as script and return the class according your need.

if (source.u_asset_class == "Software") {
    return 'cmdb_software_product_model'
} else if (source.u_asset_class == "Hardware") {
    return 'cmdb_hardware_product_model';
}

 

Vishal Birajdar
Giga Sage

Hello vikkyvivek,

 

Instead of updating target table each time set target table to " cmdb_model "

Write Transform script (Type = onBefore) present in related list of transform map.

 

VishalBirajdar7_0-1693837832775.png

 

onBefore script :

//Set the class

if (source.u_asset_class == "Software") {
            target.sys_class_name = "cmdb_software_product_model" ;
} else if (source.u_asset_class == "Hardware") {
            target.sys_class_name = "cmdb_hardware_product_model" ;
}

 

 

 

 

 

 

 

 

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates