How Not to Use Record Producers for Bulk Record Creation: A Cautionary Tale

Sandeep RanaSandeep Rana
3 min read

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

  1. Navigate and open the System Import Sets → Load Data from Application Navigator.

  1. Create an excel file [name it as per your comfort] with the following data

  1. Upload this file in the load data application and hit submit

  1. 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.

  1. You can go ahead and rename this data source and create a transform map for it.

  1. Click on the mapping assist link to map the fields.

B. Create a Record Producer

  1. Navigate to Service Catalog → Catalog Definitions → Record Producers

  1. Create a Record Producer on the Data Source Table

  1. Open the Portal Settings tab and make the attachment mandatory.

  1. 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);
  1. Navigate to the Accessibility tab and set the catalogs and category for the record producer.

  1. 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!

  1. Read how to create bulk records using record producer and attachment - the smart approach
0
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!