Best way to cleanup inactive Catalog items and its associated records.

Rajini2
Mega Sage

We need to remove catalog items that have been inactive for more than 6 months. This cleanup will include deleting associated variables, client scripts, UI policies, and UI policy actions.

Is there an out-of-the-box (OOB) solution to handle this cleanup, or should we implement it using a scheduled job?

1 ACCEPTED SOLUTION

GlideFather
Tera Patron

Hi @Rajini2,

 

there's no OOTB solution to this.

 

In a first wave, you can just deactivate the catalog items, and the associated scripts or other configurations will not be used as it's inactive. You can use a fix script or an update job but for periodically deactivating in future you will need a scheduled job, exactly as you said.

 

You will have to script a few searches > for a catalog item, use the sys id to search for catalog client scripts, flows, variables, variable sets, catalog ui policy + actions.

 

  • Variables: [item_option_new]
  • Var Sets [io_set_item]
  • Catalog UI policies [catalog_ui_policy]
  • Catalog UI Policy Actions [catalog_ui_policy_action]
  • CCS [catalog_script_client]

 And maybe you want to deactivate the user criteria (Not/Availble for), Catalog, Categories and Taxonomy topics...?

 

 

PS: wouldn't it be more effective to use the same logics immediately when a catalog item is deactivated? or why waiting half year???

_____
No AI was used in the writing of this post. Pure #GlideFather only

View solution in original post

8 REPLIES 8

Ankur Bawiskar
Tera Patron

@Rajini2 

this needs to be handled manually and carefully as you need to ensure all components related to those catalog items are either deleted or deactivated

I will recommend not deleting but just deactivate those

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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

Deepak Shaerma
Mega Sage

Hi @Rajini2 

There is no specific out-of-the-box (OOB) feature that automatically deletes inactive Catalog Items and their associated components (variables, scripts, policies) after a 6-month threshold.

You should define "inactivity" carefully. Relying only on the active=false flag isn't enough; you likely want to check the last time it was ordered.

  • Query: Look for items where active = false AND sys_updated_on < [6 months ago].

From background script you can try this:

var monthsThreshold = 6;
var cutoffDate = new GlideDateTime();
cutoffDate.addMonthsLocalTime(-monthsThreshold);

var catItem = new GlideRecord('sc_cat_item');
catItem.addQuery('active', false);
catItem.addQuery('sys_updated_on', '<', cutoffDate);
catItem.query();

while (catItem.next()) {
    gs.info('Cleaning up inactive Catalog Item: ' + catItem.name);
    
    // Deleting the item usually triggers cascade deletes for:
    // - Variables (item_option_new)
    // - Variable Sets (links)
    // - Catalog UI Policies
    // - Catalog Client Scripts
    
    catItem.deleteRecord(); 
}



Happy to help! ‌‌
To help others in the community find this solution, kindly mark this response as the Correct Answer ‌‌ and Helpful‌‌.
Warm Regards,
Deepak Sharma
Community Rising Star 2025

Dr Atul G- LNG
Tera Patron

Hi @Rajini2 

We did this exercise a few months back, and here is the approach we used:

  • Create a report to identify items for which no requests have been raised in the last six months.

  • Identify the flows configured for those items and determine whether they are part of a single flow or separate flows.

  • Check the attached variables and variable sets associated with those items.

  • Also there are SLA and report attached you need to remove that as well.
*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/dratulgrover [ Connect for 1-1 Session]

****************************************************************************************************************

Rajini2
Mega Sage

Will lean towards scheduled job. Thanks everyone!