Transform Script Processing All Entries in Source Excel Spreadsheet

steve_gannon
Tera Expert

Hello,

I am currently working on a Transform Map in ServiceNow for importing CIs into the ServiceNow CMDB from an Excel spreadsheet ("Windows linux report - test Data.xlsx" attached) generated from LanSweeper. The spreadsheet lists multiple tables/classes and I will write a Transform Map for each class using the same source file and staging table.

This particular Transform Map and script is for the cmdb_ci_computer table. Here is the script:

 

 

(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
    var assetType = source.u_assettypename.toString();

    gs.info('Processing record with AssetTypename: ' + assetType);

    if (assetType == 'Computer' || assetType == 'Desktop') {
        gs.info('Transforming record with AssetTypename: ' + assetType);
        action = 'insert_or_update';
    } else {
        gs.info('Ignoring record with AssetTypename: ' + assetType);
        return;
    }
})(source, map, log, target);

 

The source file column ‘AssetTypename’ lists the following classes:

  • Computer
  • Desktop
  • ESXi server
  • Linux
  • Virtual Machine
  • VMware Guest
  • Webserver
  • Windows

The issue I am facing is that even though the logs show that only ‘Computer’ and ‘Desktop’ are processed and the remainder are ignored, all records for all classes are inserted into the cmdb_ci_Computer table.

Here are the mappings I am using for the coalesce field and importing the CI Class using the Justification field to load it to the staging table

Source field Target field Coalesce

u_assetnamenameTRUE
u_assettypenamejustificationFALSE

 

I would appreciate any help on why all records are being processed and how to ensure that only ‘Computer’ and ‘Desktop’ records are inserted/updated into the cmdb_ci_Computer table.

Thank you!

1 ACCEPTED SOLUTION

AnveshKumar M
Tera Sage
Tera Sage

Hi @steve_gannon 

 

In your script set ignore = true, if you don't want other classes to process. Try the following script.

 

(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
    var assetType = source.u_assettypename.toString();

    gs.info('Processing record with AssetTypename: ' + assetType);

    if (assetType == 'Computer' || assetType == 'Desktop') {
        gs.info('Transforming record with AssetTypename: ' + assetType);
        action = 'insert_or_update';
    } else {
        gs.info('Ignoring record with AssetTypename: ' + assetType);
        ignore = true;
    }
})(source, map, log, target);

 

Please mark my answer helpful and accept as solution if it helped you 👍✔️

 

Thanks,
Anvesh

View solution in original post

3 REPLIES 3

AnveshKumar M
Tera Sage
Tera Sage

Hi @steve_gannon 

 

In your script set ignore = true, if you don't want other classes to process. Try the following script.

 

(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
    var assetType = source.u_assettypename.toString();

    gs.info('Processing record with AssetTypename: ' + assetType);

    if (assetType == 'Computer' || assetType == 'Desktop') {
        gs.info('Transforming record with AssetTypename: ' + assetType);
        action = 'insert_or_update';
    } else {
        gs.info('Ignoring record with AssetTypename: ' + assetType);
        ignore = true;
    }
})(source, map, log, target);

 

Please mark my answer helpful and accept as solution if it helped you 👍✔️

 

Thanks,
Anvesh

Hi Anvesh,

 

Thanks very much, working perfectly now.
Regards

Steve

@steve_gannon I'm glad that this helped you 👍

Thanks,
Anvesh