I need to build a report when asset state is changed from in stock to in use by a scheduled weekly computer sync script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2022 08:57 AM
I need to build a report when asset state is changed from in stock to in use by a scheduled weekly computer sync script. In this weekly job on function sets the CI to retire as per the criteria and one function sets the records from in stock to in use when the given condition matches. The below code sets assets from instock to inuse
function Instock(){
var comp=new GlideRecord('cmdb_ci_computer');
comp.addEncodedQuery('asset.assigned_toISEMPTY^assigned_toISNOTEMPTY^u_primary_pc=Yes^last_discoveredMORETHANasset.sys_updated_on@day@after@3');
if(testMode){
comp.setLimit(testLimit);
}
comp.query();
while(comp.next()){
count_instock++;
if(testMode){
gs.info('Asset state: '+comp.getDisplayValue('asset.install_status')+'Asset substatus: '+comp.getDisplayValue('asset.substatus')+'Asset assignedto: '+comp.getDisplayValue('asset.assigned_to')+'CI assigned to: '+comp.getDisplayValue('assigned_to'));
}
else{
var assetinstock=comp.asset;
var almasset=new GlideRecord('alm_asset');
almasset.addQuery('sys_id',assetinstock);
almasset.query();
if(almasset.next()){
almasset.install_status= '1';
almasset.substatus='';
almasset.assigned_to=comp.assigned_to;
almasset.update();
gs.info('After Update: Asset state: '+almasset.getDisplayValue('install_status')+'Asset substatus: '+almasset.getDisplayValue('substatus')+'Asset assignedto: '+almasset.getDisplayValue('assigned_to'));
}
comp.operational_status= '1';
comp.update();
}
}
}
gs.info('Asset Instock and CI assignedto not empty records: '+count_instock);
After the above job has ran, we need to get a report on the assets that are updated.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2022 09:39 AM
Hi,
Getting a report on which records that were updated by your script is a bit tricky if you are not storing any value that defines that the record was updated by the script.
Something like an script-run-date should be needed.
An example, you run the script, and you run it on a sunday to be sure that no one messes with the records, and the script updates 50 records. Then it's possible to report on updated on that specific day and updated by system.
But as soon it turns to monday, the day after, you will risk that a fulfiller changes one of these 50 records, and so is your report misleading.
So my suggestion is to create a specific field, that only this script has access to update, and write to it, and then report on that field.