Community Alums
Not applicable

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_tagISEMPTY^sys_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(); 

}

Comments
Antti Luusua
Kilo Guru

Hi! I know this is already 2 years old post but I struggle with similar issues like yourself. We started using Servicenow about a year ago and recently started using the Asset Management side. Our environment was set up by a third party and they did the initial import of our CIs from SCCM. The very early imports don't have asset tags -  this has been since fixed but I still have thousands of CIs without asset tags. 

 

Your script looks like to be the right way, but I am unsure how and where to run it? I would like them to have the next available number, which I think your script does. Thank you!

Community Alums
Not applicable

Hi Antti,

I wrote this script in 'Scripts-Background' and could be run from there.

However, now I recommend writing this script in 'Fix Scripts' in you dev instance, test it and then move to test and then to production environment.

Fix scripts can be captured in update sets and migrated to upper environments easily.

Let me know if you have any further questions.

Cheers,

Hardit Singh

rajeshraya
Giga Expert

This script worked for me with a small change.

 

var gr = new GlideRecord('cmdb_ci_vm_instance'); 
gr.addQuery("asset_tagISEMPTY^sys_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'); //UPDATED LINE HERE
gr.update(); 

}

Community Alums
Not applicable

That's great, it worked for you.

Version history
Last update:
‎02-28-2019 09:49 PM
Updated by:
Community Alums