Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Background script to update asset tag in CMDB_CI

Community Alums
Not applicable

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

RaghavSh
Mega Patron

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
LinkedIn