Setting Variable set value to many catalog items

joeycoleman
Tera Contributor

I have a situation where I have about 1100 catalog items that all need a single variable set added to them. Is there a way to do this in mass in the serviceNow portal?

 

Any help would be appreciated.

4 REPLIES 4

HIROSHI SATOH
Mega Sage

 

To add a catalog variable set to a large number of catalog items in ServiceNow, you can use the following methods:

1. Use a Catalog Item Update Script

You can use a script in ServiceNow to add the catalog variable set to all catalog items. For example, you can run a script like the one below in the Script Editor to add a catalog variable set to all catalog items.

 

※Not tested
// Specify the Variable Set ID
var variableSetId = 'Variable Set Sys ID';
// Retrieve all catalog items from the grid
var catalogItems = new GlideRecord('sc_cat_item');
catalogItems.query();
while (catalogItems.next())
{
var catalogItemId = catalogItems.getUniqueValue();
// Add the Variable Set to the Catalog Item
var catalogItemVariableSet = new GlideRecord('sc_cat_item_variable_set');
catalogItemVariableSet.initialize();
catalogItemVariableSet.cat_item = catalogItemId;
catalogItemVariableSet.variable_set = variableSetId; catalogItemVariableSet.insert();
}

Note: Make sure to test this script on a development instance and back up your data before running it.

 

2. Use Data Import Functionality

  1. Prepare Data: Prepare a CSV file or other format containing the catalog item IDs and the catalog variable set information you want to add.

  2. Data Import: Use System Import Sets > Load Data to import the CSV file and create an import set.

  3. Transform Map: Create a Transform Map to define how the imported data should be transformed.

  4. Script: Execute a script to add the catalog variable set to the catalog items based on the imported data and the Transform Map.

Sohail Khilji
Kilo Patron
Kilo Patron

Hi @joeycoleman 

 

1. Create a single variable in a variable set.

2. Use background script to add the variable set to all 1100 catalog items.

 

Below is a sample script were i wanted to add a variable set to all active catalog items., in your case you can add a encoded query in place of active filter

 

var variableSetSysId = 'YOUR_VARIABLE_SET_SYS_ID';

var catalogItemGr = new GlideRecord('sc_cat_item');
catalogItemGr.addQuery('active', true); // replace with your encoded query of 1100 catalog items.
catalogItemGr.query();

while (catalogItemGr.next()) {
    var catalogItemVariableSetGr = new GlideRecord('sc_cat_item_variable_set');
    catalogItemVariableSetGr.initialize();
    catalogItemVariableSetGr.setValue('cat_item', catalogItemGr.getSysId()); // Catalog Item sys_id
    catalogItemVariableSetGr.setValue('variable_set', variableSetSysId); // Variable Set sys_id
    catalogItemVariableSetGr.insert();
}

 

 

 

I hope this helps....


☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....

LinkedIn - Lets Connect

OlaN
Giga Sage
Giga Sage

Hi,

You can easily add all the needed catalog items to your variable set, without the need for any scripting, by navigating to the variable set (Service Catalog > Catalog Variables > Variable sets)

Open your specific variable set.

Open the "Included in" related list.

Press edit to open a slush bucket list edit, and move all the required Catalog items from the left side to the right side.

Done!

Nice one!

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn