logo

NJP

Quick Script to update empty Asset Tags of assets in Asset Management

Import · Mar 01, 2019 · article

Hi Guys,

We recently faced an issue when we moved to London. The asset tags were not being generated for the newly created assets. We fixed the issue of creation of asset tags but there were some assets left without an asset tag.

I created a 'Fix Script' for resolve this which will generate and assign unique asset tags to the assets. I did it CI class wise to keep a track of records properly. Alternatively, we can update this script and write a UI Action to generate asset tag for each asset on a form but this will be a lengthy process as you will have to go in each record and click the UI action. So, Fix script made more sense to me.

Let me know if there are any issues.

var gr = new GlideRecord('cmdb_ci_vm_instance');

gr.addQuery("asset_tagISEMPTYsys_created_on>=javascript:gs.dateGenerate('2019-02-25','00:00:00')");

gr.query();

gs.print(gr.getRowCount());

while(gr.next()){

gr.setWorkflow(false); //Trying not run any business rules.

gr.asset_tag = gr.getNextObjNumberPaddedParam('alm_asset');

gr.update();

}

View original source

https://www.servicenow.com/community/developer-articles/quick-script-to-update-empty-asset-tags-of-assets-in-asset/ta-p/2330140