Asset to CI state sync not working when asset is updated from script

Simon Christens
Kilo Sage

I have observed that sync in state between Asset and CI's (hardware state sync) might not work as intended.
If I update an Asset record manually then all fields inkl state are synced as designed, but if the Asset is updated from a script (GlideRecord) all fields EXCEPT state gets synced ?

Anyone else who have observed this behaviour ?

To reproduce:

1. Go to an hardware asset (alm_hardware) with an attached CI.
Change the state (install_status) in the Asset and see that hardware_status and substatus changes as it should on the CI.
Assigned to on asset can be set as well - and also gets synced.

Now if you do the same, just with a script:
I have tested this from a simple fix script - but i know that workflow scripts suffers from the same

var asset = new GlideRecord('alm_hardware');
asset.get('<insert asset sys_id>');
	
asset.install_status = 1;
asset.company = gs.getUser().getCompanyID();
asset.assigned_to = gs.getUserID();
asset.update();

This sync's Company, Assigned to and State is set on the Asset but the State is NOT sync'ed to the CI.
Anyone who have an idea on how to solve this ?

Regards

1 ACCEPTED SOLUTION

Hi, if i understood it correctly the state 1--->inuse it dont have any sub state to update.

sample: try this one

var asset = new GlideRecord('alm_hardware');
asset.get('00a96c0d3790200044e0bfc8bcbe5dc3');

asset.install_status = 7;//retired state
asset.substatus = 'donated';//gave  the dependent sub state
asset.company = gs.getUser().getCompanyID();
asset.assigned_to = gs.getUserID();
asset.update();

 

https://docs.servicenow.com/bundle/london-it-service-management/page/product/asset-management/concept/c_ManagingAssets.html

View solution in original post

4 REPLIES 4

Raju Koyagura
Tera Guru

I just tested the scenario in my fresh dev (London) instance and it is working perfectly fine. This may be because of some custom changes in your instance. Verify your custom changes, if you have done anything on cmdb_ci or alm_asset tables.

 

find_real_file.png

Hi Raju,

My dev instance is OOB for CI and Asset - also on London

As i say, other fields on the CI gets updated but not hardware_status and substatus on the CI.

Can you try the script a couple of time while flipping back the state manually on the Asset ?
I also have an Istanbul instance which have the exact same behaviour as my DEV instance.

Manually updated works perfectly but through script - all except State is sync'ed.

Hi, if i understood it correctly the state 1--->inuse it dont have any sub state to update.

sample: try this one

var asset = new GlideRecord('alm_hardware');
asset.get('00a96c0d3790200044e0bfc8bcbe5dc3');

asset.install_status = 7;//retired state
asset.substatus = 'donated';//gave  the dependent sub state
asset.company = gs.getUser().getCompanyID();
asset.assigned_to = gs.getUserID();
asset.update();

 

https://docs.servicenow.com/bundle/london-it-service-management/page/product/asset-management/concept/c_ManagingAssets.html

BINGO!

When using the form to update the State on Asset (substatus is not present on the form) ServiceNow itself changes the substatus field (when "in use" substatus is cleared).

This doesnt happen when setting the State through a script so that needs to be set manually as well.
Pretty inconsistent but it works.

Thanks