How Not to Use Record Producers for Bulk Record Creation: A Cautionary Tale
ServiceNow Series
Introduction
Welcome to the wild world of bulk record creation—where attachments are no longer just forgotten files but the stars of the show! Ever wish you could skip the mind-numbing task of manual data entry? Well, buckle up, because today we're diving into how to (mis)use record producers in ServiceNow to turn attachments into multiple records with ease. Spoiler alert: this approach is the wrong way to go, but hey, sometimes the worst way is the most entertaining! So grab your coffee, and let’s explore this not-so-genius trick for automating data—just don’t say I didn’t warn you!
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 Data Source 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 transformMapSysIDs = "7445b7a4c3dd92106e31f6edd401317b"; // sys id of your transform map
current.name = gs.getUserName() + " - User Import at - " + new GlideDateTime();
current.import_set_table_name = "u_test"; // Name of your import table
current.file_retrieval_method = "Attachment";
current.type = "File";
current.format = "Excel";
current.header_row = 1;
current.sheet_number = 1;
current.insert(); // need this since we want to load and transform directly
// Now its time to load the excel file into the import table
var loader = new GlideImportSetLoader();
var importSetRec = loader.getImportSetGr(current);
var ranload = loader.loadImportSetTable(importSetRec, current);
importSetRec.state = "loaded";
importSetRec.update();
// Time to run the transform with the transform map
var transformWorker = new GlideImportSetTransformerWorker(
importSetRec.sys_id,
transformMapSysIDs
);
transformWorker.setBackground(true);
transformWorker.start();
// To Avoid to create another data source, we abort the RP Insert
current.setAbortAction(true);
- 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
Alright, here’s the scoop! Right now, every time a request comes in, we’re creating a brand-new data source. Sounds fun, but it’s more like throwing a party and letting everyone bring their own snacks—total chaos!
To clean up this mess, we’d have to run a daily job to delete the extras, which can sslow things down.
But don’t worry! We’re cooking up a better way to handle this, and we’ll share it in our next blog. Get ready for a smarter approach that’ll keep things tidy and efficient! Stay tuned!