ServiceNow Data Import Using Catalog Items and Transform Maps

In ServiceNow, it's not uncommon to receive a requirement to load large amounts of catalog item data from CSV or Excel files. When dealing with significant volumes of data, the combination of Data Sources, Import Sets, and Transform Maps becomes incredibly useful. This article walks you through the process of setting up and automating the data import using these tools.

Step 1: Attach Your File to a Data Source

The first step in importing catalog item data is to attach your CSV or Excel file to a Data Source. Data Sources serve as the connection point between your file and the Import Set table in ServiceNow. Here's how you can do it:

  1. Navigate to the Data Source module in the left-hand navigation pane.
  2. Click on "New" to create a new Data Source.
  3. Attach your file to the Data Source record.
  4. Configure the details of your Data Source, ensuring it accurately reflects the structure of your data.

Step 2: Create and Configure Transform Maps

Once your Data Source is set up, the next step is to create a Transform Map to map the data from your Import Set table to the target tables in ServiceNow.

  1. Navigate to the Transform Maps module.
  2. Click "New" to create a new Transform Map.
  3. Select your Import Set table and the target table where you want the data to be inserted.
  4. Map the fields from the Import Set table to the target table. This ensures that the data is transferred correctly.
  5. Define any required transformations or business rules that should run during the import.

Step 3: Automate the Process with a Script

To automate the transformation process, you can leverage a script that runs your Transform Maps automatically whenever new data is loaded into the Import Set table. Below is an example script that you can use:

(function execute(inputs, outputs) {
var dataSourceID = inputs.dataSource;
var transformMapIDs = '02637674c4377,2637674c926d4,3ffb4763c37674c926'; //Sys_id's
var grDataSource = new GlideRecord('sys_data_source');
if (grDataSource.get(dataSourceID)) {
var loader = new GlideImportSetLoader();
var importSetRec = loader.getImportSetGr(grDataSource);
var ranload = loader.loadImportSetTable(importSetRec, grDataSource);
importSetRec.state = "loaded";
outputs.importSet = importSetRec.update();
gs.info('Unique value is: ' + importSetRec.getUniqueValue());
var importSetRecSysID = importSetRec.getUniqueValue();
var transformWorker = new GlideImportSetTransformerWorker(importSetRecSysID, transformMapIDs);
transformWorker.setBackground(true);
transformWorker.start();
}
})(inputs, outputs);

This script can be scheduled to run at a specific interval or triggered by an event, allowing for hands-off management of large data imports.

Conclusion

By utilizing Data Sources, Import Sets, and Transform Maps, you can efficiently manage large-scale data imports in ServiceNow. The automation script provided here further streamlines the process, ensuring that your catalog items are imported correctly and efficiently with minimal manual intervention.

This method is not only effective for catalog items but can also be adapted for other types of data imports in ServiceNow. Happy automating!