How to change a target table in transform map
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2023 09:36 PM
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");

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-04-2023 06:48 AM
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';
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-04-2023 07:41 AM
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.
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" ;
}
ServiceNow Developer
I know one thing, and that is that I know nothing.
- Socrates