How to do one time clean up of the asset tags mapped to retired CIs ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday - last edited yesterday
Hi All,
I want one time clean up of the asset tags mapped to retired CIs . My approach is to use fix script . Could you please suggest what should be the correct approach and Script ? I tried through fix script but it made the system slow and did not work as expected .
Please let me know if you need more info.
Thank You
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12 hours ago
Hi @1_DipikaD,
can you please provide more details about the nature of your cleanup?
Is it deactivation, deletion or what exactly?
You can also use Update job (no-code method) but it's valid to update all the records the same way - for example changing their state or any other value.
Fix script is also good option, but please provide details, this is too abstract and perhaps it could be done alternatively..
/* If my response wasn’t a total disaster ↙️ ⭐ drop a Kudos or Accept as Solution ✅ ↘️ Cheers! */
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
6 hours ago
Hi @1_DipikaD ,
For a one-time cleanup of asset tags mapped to retired CIs, using a fix script is a good approach but requires careful implementation to avoid performance issues. Here’s a recommended approach with best practices and a sample fix script outline.
Recommended Approach for Cleanup Fix Script
Batch Processing:
Avoid processing all records at once; use batching to reduce locking and improve performance.
Process records in chunks (e.g., 100 or 200 at a time).
Efficient Querying:
Query only CIs that are in Retired state and have a non-empty asset tag.
Use indexed fields (like state and asset_tag) for filtering.
Update Minimal Fields:
Only update the asset tag field or another relevant mapping field.
Use setWorkflow(false) to prevent unnecessary business rule triggers.
Scheduled Script Execution (Optional):
For very large data, consider scheduled script execution or background jobs instead of fix script.
Example Fix Script
(function() {
var batchSize = 100;
var gr = new GlideRecord('cmdb_ci');
gr.addQuery('state', 'Retired'); // adjust based on your state field values
gr.addNotNullQuery('asset_tag'); // ensure asset tag exists
gr.setLimit(batchSize);
gr.query();
var updatedCount = 0;
while (gr.next()) {
gr.setWorkflow(false); // avoid triggering workflow/business rules
gr.asset_tag = ''; // clear asset tag
gr.update();
updatedCount++;
}
gs.print('Retired CIs asset tag cleanup completed. Total records updated: ' + updatedCount);
})();
Additional Tips
Test the script in a development or sub-prod instance first.
Monitor for performance and splitting execution into multiple runs if too many records exist.
Consider logging progress in a table for large cleanups.
If asset tags are on a related table (like an asset table), adjust the GlideRecord query accordingly to unlink or clear those tags.
StepAction
Query Retired CIs | Use indexed state field and asset tag presence |
Batch Processing | Limit fixes to manageable chunks |
Disable Workflows | setWorkflow(false)to reduce overhead |
Clear Asset Tags | Set asset_tag field to empty or null |
Test & Monitor | Test in test environment and monitor performance |
