How to do one time clean up of the asset tags mapped to retired CIs ?

1_DipikaD
Kilo Sage

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

 

2 REPLIES 2

GlideFather
Tera Patron

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! */


Connectmustaq
Mega Guru

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

  1. 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).

  2. 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.

  3. Update Minimal Fields:

    • Only update the asset tag field or another relevant mapping field.

    • Use setWorkflow(false) to prevent unnecessary business rule triggers.

  4. 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

 

This approach will efficiently clean asset tags mapped to retired CIs without overloading the system, unlike an unbatched full fix script run.

 

If my response was helpful, please consider clicking the “Accept as Solution” button below my answer. Your feedback encourages me to continue assisting others.

 

Regards,
Mohammed Mustaq Shaik