- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-09-2024 12:58 PM
Hello Team,
I am inquiring about the out-of-the-box functionality in ServiceNow regarding the automatic relationship between records. Specifically, when a new record is created in either the Asset table (alm_hardware) or the CI tables under hardware and extended tables, is there a feature that automatically associates the two records (CI and Asset) based on the serial number? If such functionality exists, could you please provide details or share a link to relevant documentation?
Thank you.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-10-2024 09:22 AM
To achieve the functionality where you link an asset to an existing CI based on the serial number, you need to:
- Check if a CI with the same serial number exists.
- If it exists, link the asset to that CI.
- If it doesn’t exist, create a new CI and then link the asset to it.
Here’s how you can modify the code to implement this logic:
try {
var ci = new GlideRecord('cmdb_ci'); // Replace 'cmdb_ci' with the actual CI table name
ci.addQuery('serial_number', current.serial_number); // Replace 'serial_number' with the actual field name
ci.query();
if (ci.next()) {
// CI with the same serial number exists, so link the asset to this CI
linkAssetToCI(current, ci); // Implement this function to create the link
} else {
// CI with the same serial number does not exist, create a new CI and link the asset
var assetAndCI = new AssetandCI();
var newCI = assetAndCI.createCI(current); // This should return the new CI record
linkAssetToCI(current, newCI); // Implement this function to create the link
}
} catch (err) {
gs.addErrorMessage(err);
current.setAbortAction(true);
}
// Function to link an asset to a CI
function linkAssetToCI(asset, ci) {
// Example of linking logic, adjust based on your actual linking mechanism
asset.ci = ci.sys_id; // Replace 'ci' with the field name used to link CI in the asset record
asset.update();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-10-2024 04:16 AM
There is no functionality for this, so I think it can be achieved by modifying the existing business logic.
「Create CI on insert」
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-10-2024 09:22 AM
To achieve the functionality where you link an asset to an existing CI based on the serial number, you need to:
- Check if a CI with the same serial number exists.
- If it exists, link the asset to that CI.
- If it doesn’t exist, create a new CI and then link the asset to it.
Here’s how you can modify the code to implement this logic:
try {
var ci = new GlideRecord('cmdb_ci'); // Replace 'cmdb_ci' with the actual CI table name
ci.addQuery('serial_number', current.serial_number); // Replace 'serial_number' with the actual field name
ci.query();
if (ci.next()) {
// CI with the same serial number exists, so link the asset to this CI
linkAssetToCI(current, ci); // Implement this function to create the link
} else {
// CI with the same serial number does not exist, create a new CI and link the asset
var assetAndCI = new AssetandCI();
var newCI = assetAndCI.createCI(current); // This should return the new CI record
linkAssetToCI(current, newCI); // Implement this function to create the link
}
} catch (err) {
gs.addErrorMessage(err);
current.setAbortAction(true);
}
// Function to link an asset to a CI
function linkAssetToCI(asset, ci) {
// Example of linking logic, adjust based on your actual linking mechanism
asset.ci = ci.sys_id; // Replace 'ci' with the field name used to link CI in the asset record
asset.update();
}