Introduction
Welcome to a world where bulk record creation doesn’t have to be a nightmare! Say goodbye to messy methods and hello to a smarter approach that’ll make you wonder why you didn’t try this sooner. In this guide, I’ll show you how to correctly harness record producers in ServiceNow—no more headaches, just seamless data transformation. So, grab a snack, and let’s start making bulk uploads a breeze!
Creating the Masterpiece
A. Create Data Source and Transform Map
- Navigate and open the System Import Sets → Load Data from Application Navigator.
- Create an Excel file [name it as per your comfort] with the following data
- Upload this file in the load data application and hit submit
- Once data is loaded, you will see a data source being generated. To check, navigate to System Import Sets → Administration → Data Sources and sort by latest created date.
- You can go ahead and rename this data source and create a transform map for it.
- Click on the mapping assist link to map the fields.
B. Create a Record Producer
- Navigate to Service Catalog → Catalog Definitions → Record Producers
- Create a Record Producer on the Incident Table
Open the Portal Settings tab and make the attachment mandatory.
Back in the What it will contain tab, copy and paste the code below into the script section.
var data_source = {
table: "sys_data_source",
sys_id: "fceef841c31916106e31f6edd4013182",
transformMapSysID: "58fe7405c31916106e31f6edd401316d",
};
var sys_attachment = GlideSysAttachment();
// Delete existing attachment from Data Source
var data_source_record = new GlideRecord(data_source.table);
data_source_record.get(data_source.sys_id);
sys_attachment.deleteAll(data_source_record); // delete all existing attachment from data source
// once attachments are deleted, copy the attachment from user record to data source record.
sys_attachment.copy(
"incident",
current.sys_id.toString(),
data_source.table,
data_source.sys_id
);
// once attachment is copied, start the transformation process.
// Now its time to load the excel file into the import table
var loader = new GlideImportSetLoader();
var importSetRec = loader.getImportSetGr(data_source_record);
var ranload = loader.loadImportSetTable(importSetRec, data_source_record);
importSetRec.state = "loaded";
importSetRec.update();
// Time to run the transform with the transform map
var transformWorker = new GlideImportSetTransformerWorker(
importSetRec.sys_id,
data_source.transformMapSysID
);
transformWorker.setBackground(true);
transformWorker.start();
current.setAbortAction(true); // this will not create a blank record in user table
Navigate to the Accessibility tab and set the catalogs and category for the record producer.
Now, if you Navigate to Portal and Search for this record producer, you will find it. You can attach the file and hit submit and incidents from the file will be generated on the incident table.
Drawbacks
While this approach makes bulk record creation smooth and reliable, it’s not quite the pinnacle of efficiency. The downside? The code can be a bit lengthy and might feel like overkill if you’re looking for a simpler solution. But fear not! In my next blog, I’ll reveal a streamlined method to achieve the same results with just a few lines of code. So stay tuned for an even quicker and cleaner way to handle bulk uploads!