Add a CI to an existing asset

pjrichertctek
Tera Contributor

We have a situation where a client created assets where the model categories were blank, and then created cis. The issue, now that we've corrected the categories, is how to add the cis that exist in the correct classes to the existing assets?

2 REPLIES 2

Amarjeet Pal
Kilo Sage
Kilo Sage

Hello @pjrichertctek ,

 

Let me know how many such records are there , if count of records are more you can go with the automation script and you can run in Fix scripts.

 

Here is an example script that you could use to update the model category for CIs and associate them with assets in ServiceNow:

```
// Set up a GlideRecord query to retrieve all CIs that need to be updated
var ciGR = new GlideRecord('cmdb_ci');
ciGR.addQuery('model_category', '');
ciGR.query();

while (ciGR.next()) {
  // Update the model category for each CI
  ciGR.model_category = 'your_model_category';
  ciGR.update();
  
  // Retrieve the asset associated with this CI, if any
  var assetGR = new GlideRecord('alm_asset');
  assetGR.addQuery('ci', ciGR.sys_id);
  assetGR.query();
  
  while (assetGR.next()) {
    // Associate the correct CI with the asset
    assetGR.ci = ciGR.sys_id;
    assetGR.update();
  }
}
```

Note that this is just an example script and may need to be modified based on your specific requirements. It's also important to test any scripts thoroughly in a non-production environment before running them in production.

Please mark the response Helpful , if it has given some light to your block path.

 

Thanks,

Amarjeet Pal

Ashok Sasidhara
Tera Sage
Tera Sage

You should first verify that all the corrected model categories have both Asset class and CI class associated with it. Once that is verified, you can create an excel template to do a bulk update of all the asset records which needs to be linked with CIs.  i.e. The 'Configuration item' field of all the required asset records should be populated in the template with the exact name of existing CIs to be linked with each asset record. It is better to follow this method for updating the data instead of using a script. This will give better control over what will be updated and also make it easier to validate the populated data.