- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-29-2023 12:04 AM
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_assetname | name | TRUE |
u_assettypename | justification | FALSE |
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!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-29-2023 12:09 AM - edited 09-29-2023 12:10 AM
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 👍✔️
Anvesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-29-2023 12:09 AM - edited 09-29-2023 12:10 AM
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 👍✔️
Anvesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-29-2023 12:42 AM
Hi Anvesh,
Thanks very much, working perfectly now.
Regards
Steve
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-29-2023 01:19 AM
@steve_gannon I'm glad that this helped you 👍
Anvesh