How can I replace multiple variables with one variable set for multiple catalog items?

Guna Shalini
Tera Contributor

There are multiple variables with the name 'comment' or 'comments' and every variable has been created under different catalog items. I could see 332 variables under the same name. I need to replace all these variables with one variable set under the name comments. Please help regarding this.

7 REPLIES 7

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

then associate those variables to a variable set

Then link that variable set to the catalog items you want

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

@Guna Shalini 

I have shared solution for the short cut 2 years ago

Including the variable set in multiple catalog items in one go

Sharing the script and other approach again here

1) script based

2) from UI

1) Script based: this table (io_set_item) holds the mapping of variable set and catalog item

Write this in background script

// give here the catalog item sys_id in the array

var arr = ['catalogItem1SysId','catalogItem2SysId','catalogItem3SysId'];

var gr = new GlideRecord('io_set_item');
for(var i=0;i<arr.length;i++){
gr.initialize();
gr.sc_cat_item = arr[i];
gr.order = 100;
gr.variable_set = 'variable set sys_id'; // give here the variable set sys_id here
gr.insert();
}

2) UI Based:

1. Go to variable set and add related list 'Included in' on form if its not already there

2. Click on edit button on the related list

3. There you can select all your items at once. Use filters to narrow down the list

 

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

@Guna Shalini 

Hope you are doing good.

Did my reply answer your question?

If my response helped please close the thread by marking appropriate response as correct so that it benefits future readers.

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Mohit Kaushik
Mega Sage
Mega Sage

Hi Guna,

 

You can start by creating a variable set. And create the variable with name as 'comment(s)' under the variable set. Then go to each of your catalog item and select the variable set section and by clicking on edit button you can bring this variable set on your catalog item.

How to create Variable set

 

Please mark this correct and helpful based on the impact.

 

Thanks,

Mohit Kaushik

Thanks,
Mohit Kaushik
ServiceNow MVP (2023-2025)