CI Hardware Status and Substatus not syncing with Asset Install Status and Substate

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2020 02:24 PM
Hello all you fine people!
I recently performed an import of CI records and unfortunately my Asset - CI Hardware Status mapping was not in place prior to doing the import. The data was heavily modified before this was discovered so unfortunately I can't just reimport the data and start fresh. So I'm looking for a script solution to update "assigned to", "hardware status", and "substatus" fields to trigger the AssetAndCISynchronizer script include which triggers "on change" from the Update Asset fields on change BR.
I've tried running scripts which modify other fields and update the record but that doesn't trigger the BR / Script Include. Likely because the script include seems to be written in such a way that it only triggers if the referenced fields have a change(a very efficient check, but super annoying in my case). I am strongly hesitant to modify the behavior of the OOB script include given my very novice experience.
To complicate matters even further - manually modifying these attributes on imported CIs does not appear to update the asset record as I would expect it to. However, if I manually create a new CI and modify the fields the result is that all fields are updated on both tables, as expected.
It seems to me there is some disassociation occurring between the CI and the Asset, even though both appear correctly on their respective forms (asset.ci and cmdb_ci_pc_hardware.asset) and can be navigated back and forth.
I've also tried running a script that queries the value of these fields on the CI and then populates the value on the associated Asset. As follows:
// Update Asset record field values with CI record field values
var grCmdb = new GlideRecord('cmdb_ci_pc_hardware'); //create glide record on cmdb table
grCmdb.query(); //query all records in table
while(grCmdb.next()) {
var ciSysId = grCmdb.asset; //get sys_id for CI asset
var grAsset = new GlideRecord('alm_asset'); //create glide record on asset table
grAsset.addQuery('sys_id',ciSysId); //where sys_id from Asset == sys_id from Asset on CI table
grAsset.query(); // run query
if(grAsset.next()) {
grAsset.install_status = grCmdb.hardware_status;
grAsset.substatus = grCmdb.substatus;
grAsset.assigned_to = grCmdb.assigned_to;
grAsset.setWorkflow(false);
grAsset.update(); //commit update
}
}
To clarify some specifics:
This is NOT related to the "install status" known issue referenced here https://hi.service-now.com/kb_view.do?sysparm_article=KB0717902
I'm using "hardware status" and "substatus". These field mappings have been established in the Asset - CI Hardware Status mapping table. All maps are verified to be bidirectional and active.
As always, thank you for any assistance you may be able to provide!
Daniel
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2020 02:33 PM
Run below code in fix script and allow fix to run in background which uses OOB script include to sync asset and CI data.
syncAllAssetRecords();
function syncAllAssetRecords() {
var grCI = new GlideRecord("cmdb_ci_pc_hardware");
grCI.query();
var updateCount = 0;
while(grCI.next()){
var ca = new AssetAndCISynchronizer();
ca.syncRecords(grCI, 'alm_asset');
updateCount++;
}
}
gs.print('Records Synced: '+ updateCount);
Regards,
Sachin

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2020 03:13 PM
Unfortunately, that doesn't do the trick. I believe this is related to the "check" for change in the AssetandCISynchonizer script.
Thanks for the thought.
Daniel