Add a CI to an existing asset
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-22-2023 07:18 AM
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-23-2023 04:59 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-27-2023 08:22 AM
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.