Background script to update asset tag in CMDB_CI

Community Alums
Not applicable
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-22-2022 06:29 PM
Hi -
I have a requirement to update the asset tag field in CMDB table where the asset_tag is empty based on the asset_tag field in the alm_asset table. The assetandcisynchorizer would work when the cmdb_ci record gets updated but we want to run a cleanup now and fix the records.
I need help with a background script. can someone please help?
Thank you
1 REPLY 1
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-22-2022 10:18 PM
Try below in background or fix script.
var asset = new GlideRecord('alm_asset');
asset.addEncodedQuery('ciISNOTEMPTY');
asset.query();
while(asset.next())
{
var ci = new GlideRecord('cmdb_ci');
ci.addEncodedQuery('asset_tagISEMPTY') // will check empty asset tags on cmdb_ci table
ci.addQuery('sys_id',asset.ci);
if(ci.next())
{
ci.asset_tag = asset.asset_tag;
ci.update();
}
}
Note: All scripts should be tested in dev before executing in prod.
Raghav
MVP 2023