- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-26-2023 11:50 PM
There are 20k assets which doesn't have CI linked to it because the model category of those assets doesn't have a CI linked to it.
We need to update the model category to a new model category which has CI class linked to it. Does by updating it, will it create a corresponding CI?
Or we need to write a background script to do it. If yes, can you please let me know how to do it
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-27-2023 03:12 AM - edited ‎07-27-2023 06:30 AM
To create CIs for the 20k assets that currently do not have CI linked to them, you will need to write a background script. The script will perform the necessary updates and create the corresponding CIs.
Here's a general outline of the steps you can follow to achieve this:
Identify the new model category that has the desired CI class linked to it. Make sure the CI class is configured with the appropriate attributes and relationships to represent the assets correctly.
Create a background script that queries the assets without linked CIs and then updates their model category to the new one with the desired CI class.
For each updated asset, create a new CI using the CI class associated with the new model category. Populate the CI attributes based on the information from the asset record.
Establish any relationships between the newly created CIs and other CIs or records in the system if required.
Test the script thoroughly in a development or test environment before running it in production to ensure it works as expected and doesn't cause any unintended consequences.
Here's a sample pseudo-code to give you an idea of how the script might look like:
// Step 1: Identify the asset records without linked CIs and update their model category
var assetGr = new GlideRecord('your_asset_table');
assetGr.addNullQuery('linked_ci'); // Add a query to find assets without linked CIs
assetGr.query();
while (assetGr.next()) {
// Step 2: Update the model category to the new one with CI class linked to it
assetGr.model_category = 'new_model_category_sys_id'; // Replace 'new_model_category_sys_id' with the actual sys_id of the new model category
assetGr.update(); // Step 3: Create a new CI record with the CI class associated with the new model category
var ciGr = new GlideRecord('cmdb_ci'); // Replace 'cmdb_ci' with the appropriate CI class name
ciGr.initialize();
ciGr.name = assetGr.name; // Use appropriate attribute mappings based on your configuration
// Populate other CI attributes based on assetGr fields
ciGr.insert();
// Step 4: Establish any necessary relationships with other CIs or records
// For example, if the asset is associated with a location, set the location relationship on the CI
// Step 5: Repeat the process for all assets without linked CIs
}
Please note that the actual implementation may vary based on your specific configuration, CI class structure, and relationships. It's essential to thoroughly understand your environment and test the script before applying it to a large number of records. Additionally, ensure you have appropriate permissions to modify asset records and create CIs through the script.
Regards,
Piyush Sain
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-27-2023 03:12 AM - edited ‎07-27-2023 06:30 AM
To create CIs for the 20k assets that currently do not have CI linked to them, you will need to write a background script. The script will perform the necessary updates and create the corresponding CIs.
Here's a general outline of the steps you can follow to achieve this:
Identify the new model category that has the desired CI class linked to it. Make sure the CI class is configured with the appropriate attributes and relationships to represent the assets correctly.
Create a background script that queries the assets without linked CIs and then updates their model category to the new one with the desired CI class.
For each updated asset, create a new CI using the CI class associated with the new model category. Populate the CI attributes based on the information from the asset record.
Establish any relationships between the newly created CIs and other CIs or records in the system if required.
Test the script thoroughly in a development or test environment before running it in production to ensure it works as expected and doesn't cause any unintended consequences.
Here's a sample pseudo-code to give you an idea of how the script might look like:
// Step 1: Identify the asset records without linked CIs and update their model category
var assetGr = new GlideRecord('your_asset_table');
assetGr.addNullQuery('linked_ci'); // Add a query to find assets without linked CIs
assetGr.query();
while (assetGr.next()) {
// Step 2: Update the model category to the new one with CI class linked to it
assetGr.model_category = 'new_model_category_sys_id'; // Replace 'new_model_category_sys_id' with the actual sys_id of the new model category
assetGr.update(); // Step 3: Create a new CI record with the CI class associated with the new model category
var ciGr = new GlideRecord('cmdb_ci'); // Replace 'cmdb_ci' with the appropriate CI class name
ciGr.initialize();
ciGr.name = assetGr.name; // Use appropriate attribute mappings based on your configuration
// Populate other CI attributes based on assetGr fields
ciGr.insert();
// Step 4: Establish any necessary relationships with other CIs or records
// For example, if the asset is associated with a location, set the location relationship on the CI
// Step 5: Repeat the process for all assets without linked CIs
}
Please note that the actual implementation may vary based on your specific configuration, CI class structure, and relationships. It's essential to thoroughly understand your environment and test the script before applying it to a large number of records. Additionally, ensure you have appropriate permissions to modify asset records and create CIs through the script.
Regards,
Piyush Sain
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-28-2023 01:07 AM
@Swarnarghya If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
Regards,
Piyush Sain
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-28-2023 03:44 AM
Background script is NOT recommended for this as OOB method is available as mentioned below:
1. Go to 'Model categories' from the application navigator
2. Open Model category record for any CI class for whom you wish to link 'Asset class'
3. Populate the 'Asset class' field. Make sure to finalize the asset class by discussing with all ITAM stakeholders before doing this. The 'Asset class' field becomes non-editable after it is populated.
4. 'Create assets' button will appear after the 'Asset class' is updated as Asset, Hardware or Facility. Clicking 'Create assets' will create assets in the selected Asset table for all the CIs present in the CI class associated with the model category (If any individual models which are part of this model category are configured to NOT create assets, then assets won't be created for them)
The steps are indicated in the following screenshots. For each model category where you are going to link with an asset class, you need to also first make sure that there is a business reason to consider them as assets (i.e. If information like procurement, financial, contractual or warranty data needs to be tracked & managed for them). Also you should not create all 20k assets in one go. After shortlisting the relevant model categories to be linked to assets, please review the CI Class data first for one model category to see if any changes are required before creating assets and then proceed to click 'Create assets' for that model category. After that, review the created asset data & make any corrections identified before proceeding to do the same for the next model category.