POC on creating catalog items in bulk

EmmadishettV
Tera Contributor

As a ServiceNow platform developer who works in delivering catalog items to business, I want to create a poc on creating catalog items in bulk with diff variables or same variable set.This would make the job easier for handling multiple catalog items. Please drop-in your ideas to approach this or do we have any existing OOB functionality to achieve this

1 REPLY 1

rahulswami
Tera Contributor

Hi @EmmadishettV 

There is no OOB feature for creating catalog items in bulk, but here are a few ways to approach your POC.

Start with Variable Sets. For anything shared across items, build the Variable Set once and attach it to many items instead of recreating variables each time. The link table is io_set_item (sc_cat_item, variable_set), so attaching one set to 50 items is just 50 rows.

Import Set + Transform Map is the most reusable option. Load a spreadsheet of item definitions, then run two transform maps:

  • Map 1 onto sc_cat_item (name, short description, catalog, category, workflow), coalescing on name
  • Map 2 onto item_option_new for item specific variables, with cat_item populated from Map 1

The real benefit is that business owners can fill the sheet themselves.

Fix Script is the quickest way to prove it out:

var VAR_SET = '<variable_set_sys_id>';
var items = [
  {name: 'Laptop Request', short_description: 'Request a laptop', category: '<cat_sys_id>'},
  {name: 'Monitor Request', short_description: 'Request a monitor', category: '<cat_sys_id>'}
];

items.forEach(function(o) {
  var gr = new GlideRecord('sc_cat_item');
  gr.initialize();
  gr.name = o.name;
  gr.short_description = o.short_description;
  gr.sc_catalogs = '<catalog_sys_id>';
  gr.category = o.category;
  var id = gr.insert();

  var m2m = new GlideRecord('io_set_item');
  m2m.initialize();
  m2m.sc_cat_item = id;
  m2m.variable_set = VAR_SET;
  m2m.insert();
});

 

or item specific variables, insert into item_option_new with cat_item set. To get the type values right, check an existing variable of that type instead of guessing the integer.

A couple of other options worth checking: the OOB Copy UI action clones an item along with its variables, useful when items are nearly identical, and Catalog Builder templates help standardise what gets created, though still one item at a time.

One caution: do this in a dedicated update set, since scripted inserts on sc_cat_item are easy to create and painful to unwind.

If this helped to answer your query, please mark it helpful & accept the solution.