How Not to Use Record Producers for Bulk Record Creation: A Cautionary Tale
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!
Related Link
Subscribe to my newsletter
Read articles from Sandeep Rana directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Sandeep Rana
Sandeep Rana
I'm a dedicated ServiceNow Developer and Analyst with four years of experience. I previously worked at Deloitte and am currently with QBRAINX. My journey in technology started as a freelance web developer, where I developed a passion for creating user-friendly web solutions. In my current role, I specialize in various aspects of ServiceNow, including Portal design, Flow, Integration, Common Configuration, and HRSD modules. What truly excites me is experimenting with the amalgamation of web development and ServiceNow capabilities. My work allows me to blend creativity with technical prowess, ensuring the solutions I create are both functional and intuitive. I bridge the gap between complex technical concepts and user-friendly designs, striving for excellence in every project. Beyond my professional endeavors, I'm a lifelong learner, constantly exploring new technological horizons. My enthusiasm for innovation fuels my commitment to delivering high-quality results. If you share a passion for technology and innovation, I'd love to collaborate and create something extraordinary together. Let's connect!