How to map fields when it's not present in target table through script

Aastha
Tera Contributor

I have created transform map , some fields are auto map , some fields which are reference list are mapped by field script, but fields which are string type are not mapped due to which its data is not populated in cmdb. How can I map these fields.

 

 

 

Transform script :- 

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

    // Add your code here
    if (source.u_class == "Computer") {
        target.sys_class_name = 'cmdb_ci_computer';
        //target.location = '8379ea471b2b415020fabb7f034bcbb9';
        //gs.log("location is this: "+ target.location);
        target.ram = source.u_ram;
        target.os_domain = source.u_os_domain; ------ (These fields are not mapped)
        target.asset = source.u_asset;
        target.os_version = source.u_os_version;
        target.os_service_pack = source.u_os_service_pack;
        target.dns_domain = source.u_dns_domain;
        target.disk_space = source.u_disk_space;
        target.cpu_manufacturer = source.u_cpu_manufacturer;
        target.cpu_type = source.u_cpu_type;
        target.cpu_speed = source.u_cpu_speed;
        
        //gs.log("ram is :"+ source.u_ram);
        // target.location = source.u_location;



        // target.operating_system = source.u_operating_system;
        // target.os_version = source.u_os_version;
        // target.os_domain = source.u_os_domain;
        // target.support_group = source.u_support_group;
        // target.assigned_to = source.u_assigned_to;


    }
    if (source.u_class == "Server") {
        gs.log("script in this also");
        target.sys_class_name = 'cmdb_ci_server';
        target.ram = source.u_ram;
        target.location = source.u_location;
        target.support_group = source.u_support_group;
        target.vendor = source.u_vendor;
        target.used_for = source.u_used_for;
        target.monitor = source.u_monitor;
        target.host_name = source.u_host_name;
        target.os_domain = source.u_os_domain;
        target.operating_system = source.u_operating_system;
        target.os_version = source.u_os_version;
        target.cpu_manufacturer = source.u_cpu_manufacturer;

    }
    if (source.u_class == "Windows Server") {
        target.sys_class_name = 'cmdb_ci_win_server';
    }
    if (source.u_class == "Linux Server") {
        target.sys_class_name = 'cmdb_ci_linux_server';
    }
    if (source.u_class == "ESX Server") {
        target.sys_class_name = 'cmdb_ci_esx_server';
    }
    if (source.u_class == "Network") {
        target.sys_class_name = 'cmdb_ci_netgear';
        target.location = source.u_location;
        target.support_group = source.u_support_group;
        target.vendor = source.u_vendor;
        target.device_type = source.u_device_type;
        target.location = source.u_location;
        target.monitor = source.u_monitor;
        target.ports = source.u_ports;
        target.firmware_version = source.u_firmware_version;


    }
    if (source.u_class == "Printer") {
        target.sys_class_name = 'cmdb_ci_printer';
        target.location = source.u_location;
        target.model_name = source.u_model_name;
        target.support_group = source.u_support_group;

    }
    if (source.u_class == "Vmware") {
        target.sys_class_name = 'cmdb_ci_vm_vmware';
        target.full_name = source.u_full_name;
        target.api_version = source.u_api_version;
        target.url = source.u_url;
        target.support_group = source.u_support_group;
        target.vendor = source.u_vendor;
        target.used_for = source.u_used_for;
    }
    if (source.u_class == "MS SQL Database") {
        target.sys_class_name = 'cmdb_ci_db_mssql_database';
        target.support_group = source.u_support_group;
        target.vendor = source.u_vendor;
        target.used_for = source.u_used_for;
        target.monitor = source.u_monitor;
        target.is_clustered = source.u_is_clustered;
        target.version = source.u_version;
        target.tcp_ports = source.u_tcp_ports;
    }
    if (source.u_class == "Postgre SQL") {
        target.sys_class_name = 'cmdb_ci_db_postgresql_instance';
        target.support_group = source.u_support_group;
        target.vendor = source.u_vendor;
        target.used_for = source.u_used_for;
        target.monitor = source.u_monitor;
        target.is_clustered = source.u_is_clustered;
        target.version = source.u_version;
        target.tcp_ports = source.u_tcp_ports;
    }
    if (source.u_class == "Hbase Instance") {
        target.sys_class_name = 'cmdb_ci_db_hbase_instance';
        target.support_group = source.u_support_group;
        target.vendor = source.u_vendor;
        target.used_for = source.u_used_for;
        target.monitor = source.u_monitor;
        target.is_clustered = source.u_is_clustered;
        target.version = source.u_version;
        target.tcp_ports = source.u_tcp_ports;
    }
    if (source.u_class == "Mongo DB Instance") {
        target.sys_class_name = 'cmdb_ci_mongo_database';
        target.support_group = source.u_support_group;
        target.vendor = source.u_vendor;
        target.used_for = source.u_used_for;
        target.monitor = source.u_monitor;
        target.is_clustered = source.u_is_clustered;
        target.version = source.u_version;
        target.tcp_ports = source.u_tcp_ports;
    }
    if (source.u_class == "IP Router") {
        target.sys_class_name = 'cmdb_ci_ip_router';
        target.location = source.u_location;
        target.support_group = source.u_support_group;
        target.vendor = source.u_vendor;
        target.device_type = source.u_device_type;
        target.location = source.u_location;
        target.monitor = source.u_monitor;
        target.ports = source.u_ports;
        target.firmware_version = source.u_firmware_version;
    }
    if (source.u_class == "IP Switch") {
        target.sys_class_name = 'cmdb_ci_ip_switch';
        target.location = source.u_location;
        target.support_group = source.u_support_group;
        target.vendor = source.u_vendor;
        target.device_type = source.u_device_type;
        target.location = source.u_location;
        target.monitor = source.u_monitor;
        target.ports = source.u_ports;
        target.firmware_version = source.u_firmware_version;
    }
    if (source.u_class == "IP Firewall") {
        target.sys_class_name = 'cmdb_ci_ip_firewall';
        target.location = source.u_location;
        target.support_group = source.u_support_group;
        target.vendor = source.u_vendor;
        target.device_type = source.u_device_type;
        target.location = source.u_location;
        target.monitor = source.u_monitor;
        target.ports = source.u_ports;
        target.firmware_version = source.u_firmware_version;
    }
    if (source.u_class == "Wireless Access Point") {
        target.sys_class_name = 'cmdb_ci_wap_network';
        target.location = source.u_location;
        target.support_group = source.u_support_group;
        target.vendor = source.u_vendor;
        target.device_type = source.u_device_type;
        target.location = source.u_location;
        target.monitor = source.u_monitor;
        target.ports = source.u_ports;
        target.firmware_version = source.u_firmware_version;
    }
    if (source.u_class == "Load Balancer") {
        target.sys_class_name = 'cmdb_ci_lb';
        target.vendor = source.u_vendor;
        target.location = source.u_location;
        target.support_group = source.u_support_group;
    }
    if (source.u_class == "Hardware") {
        target.sys_class_name = 'alm_hardware';
        target.display_name = source.u_display_name;
        target.model_category = source.u_model_category;
        target.model = source.u_model;
        target.configuration_item = source.u_configuration_item;
        target.assigned_to = source.u_assigned_to;
        target.managed_by = source.u_managed_by;
        target.owned_by = source.u_owned_by;
        target.location = source.u_location;
        target.department = source.u_department;
        target.company = source.u_company;
        target.request_line = source.u_request_line;
        target.invoice_number = source.u_invoice_number;
        target.cost = source.u_cost;
        target.vendor = source.u_vendor;
        target.purchased = source.u_purchased;
        target.po_number = source.u_po_number;
        target.opened = source.u_opened;
        target.gl_account = source.u_gl_account;
        target.cost_center = source.u_cost_center;
        target.acquistion_method = source.u_aquistion_method;
        target.expenditure_type = source.u_expenditure_type;
        target.disposal_reason = source.u_disposal_reason;
        target.beneficiary = source.u_beneficiary;
        target.resale_price = source.u_resale_price;
        target.scheduled_retirement = source.u_scheduled_retirement;
        target.retired_date = source.u_retired_date;
        target.depreciation = source.u_depreciation;
        target.depreciation_effective_date = source.u_depreciation_effective_date;
        target.salvage_class = source.u_salvage_class;
    }



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

 

 
There are so many tables so user can populate in any table so according to the sheet uploaded by user table is selected in which data is updated. There are so many tables therefore I have select base 
9 REPLIES 9

Ankur Bawiskar
Tera Patron
Tera Patron

@Aastha  

if the fields are not mapped via field map then you need to handle those in onBefore transform script

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

Thanks for your replay can you share onBefore transform script or where I can find that.

@Aastha  

the script you shared is onBefore?

if yes then there only you can add it

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

Hi @Ankur Bawiskar

 

Here I have written that Script

Aastha_1-1687937477248.png