- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-23-2024 07:21 AM
In CMDB_CI table I need to avoid duplicate data inserstion.
Can it be achived via Discovery or do we need to write a script??
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-23-2024 10:43 AM
Hi @SandeepKSingh ,
You can restrict duplicate CIs in 'cmdb_ci' table in both ways.
1. Discovery - If you follow discovery approach then update existing CIs instead of creating same new record, so that have to build Identification rule.
Doc Link :
Identification rules (servicenow.com)
CMDB Identification and Reconciliation rules | CMDB IRE ServiceNow | Part 1 - YouTube
ServiceNow CMDB Identification Rule Demo | CMDB IRE Live Demo (youtube.com)
2. Custom Script - We can create before /insert custom BR on 'cmdb_ci' table & also restrict the duplicate CI's entry in 'cmdb_ci' table.
(function executeRule(current, previous /*null when async*/) {
//insert or update operation check
if (current.operation() == 'insert' || current.operation() == 'update')
{
var ciCheck = new GlideRecord('cmdb_ci');
ciCheck.addQuery('serial_number', current.serial_number);
ciCheck.query();
if (ciCheck.next())
{
gs.addErrorMessage(' CI Record with this serial number already exists in table.');
current.setAbortAction(true); // Abort the insert operation
}
}
Please mark helpful & accept answer if it's really worthy for you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-23-2024 10:52 PM
---- >Avoiding Duplicates via Discovery:
Discovery in ServiceNow is designed to automatically detect and handle duplicates in the CMDB. It uses identifiers and reconciliation rules to prevent duplicate entries.
- Identifiers and Reconciliation Rules:
- Identifiers: Discovery uses identifiers to determine if a CI already exists in the CMDB. These identifiers are a set of attributes that uniquely identify a CI (e.g., serial number, hostname).
- Reconciliation Rules: These rules determine which source (e.g., Discovery, Import Sets) has authority to update specific fields on a CI.
When Discovery runs, it checks the identifier rules for the CI class it’s populating. If it finds a CI that matches the identifiers, it updates that CI rather than creating a new one, thereby avoiding duplicates.
- Steps to Configure:
- Navigate to Configuration > CI Class Manager.
- Select the appropriate CI class (e.g.,
cmdb_ci_computer
). - Review and modify the identifiers to ensure they correctly match the unique properties of your CIs.
- Set up reconciliation rules if needed, under Configuration > Reconciliation.
Advantages:
- Automated: Minimal manual intervention.
- Consistent: Ensures consistency across CIs based on defined rules.
---- >Avoiding Duplicates via Scripting:
In cases where Discovery is not sufficient or you need additional logic, you can use scripting (like a Business Rule) to prevent duplicate entries.
Example Business Rule: You can create a Business Rule on the cmdb_ci
table that checks for duplicates before inserting a new CI.
- Trigger: Before Insert
- Condition: None (applies to all insert operations)
- Script:
(function executeRule(current, previous /*null when async*/) { // Query the cmdb_ci table to check for a duplicate entry var ci = new GlideRecord('cmdb_ci'); ci.addQuery('name', current.name); ci.query(); // If a record with the same name exists, prevent insert if (ci.next()) { gs.addErrorMessage('Duplicate CI detected: A CI with the name "' + current.name + '" already exists.'); current.setAbortAction(true); // Prevent the insert } })(current, previous);
If you found my response helpful, I would greatly appreciate it if you could mark it as "Accepted Solution" and "Helpful."
Your support not only benefits the community but also encourages me to continue assisting. Thank you so much!
Thanks and Regards
Ravi Gaurav | ServiceNow MVP 2025,2024 | ServiceNow Practice Lead | Solution Architect
CGI
M.Tech in Data Science & AI
ï”— YouTube: https://www.youtube.com/@learnservicenowwithravi
ï”— LinkedIn: https://www.linkedin.com/in/ravi-gaurav-a67542aa/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-23-2024 09:56 AM
Hi @SandeepKSingh ,
have you identified why data is injected multiple times? Is data only inserted from discovery?
my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
Best regards
Anders
If my answer has helped with your question, please mark my answer as the accepted solution and give a thumbs up.
Best regards
Anders
Rising star 2024
MVP 2025
linkedIn: https://www.linkedin.com/in/andersskovbjerg/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-23-2024 10:43 AM
Hi @SandeepKSingh ,
You can restrict duplicate CIs in 'cmdb_ci' table in both ways.
1. Discovery - If you follow discovery approach then update existing CIs instead of creating same new record, so that have to build Identification rule.
Doc Link :
Identification rules (servicenow.com)
CMDB Identification and Reconciliation rules | CMDB IRE ServiceNow | Part 1 - YouTube
ServiceNow CMDB Identification Rule Demo | CMDB IRE Live Demo (youtube.com)
2. Custom Script - We can create before /insert custom BR on 'cmdb_ci' table & also restrict the duplicate CI's entry in 'cmdb_ci' table.
(function executeRule(current, previous /*null when async*/) {
//insert or update operation check
if (current.operation() == 'insert' || current.operation() == 'update')
{
var ciCheck = new GlideRecord('cmdb_ci');
ciCheck.addQuery('serial_number', current.serial_number);
ciCheck.query();
if (ciCheck.next())
{
gs.addErrorMessage(' CI Record with this serial number already exists in table.');
current.setAbortAction(true); // Abort the insert operation
}
}
Please mark helpful & accept answer if it's really worthy for you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-23-2024 10:52 PM
---- >Avoiding Duplicates via Discovery:
Discovery in ServiceNow is designed to automatically detect and handle duplicates in the CMDB. It uses identifiers and reconciliation rules to prevent duplicate entries.
- Identifiers and Reconciliation Rules:
- Identifiers: Discovery uses identifiers to determine if a CI already exists in the CMDB. These identifiers are a set of attributes that uniquely identify a CI (e.g., serial number, hostname).
- Reconciliation Rules: These rules determine which source (e.g., Discovery, Import Sets) has authority to update specific fields on a CI.
When Discovery runs, it checks the identifier rules for the CI class it’s populating. If it finds a CI that matches the identifiers, it updates that CI rather than creating a new one, thereby avoiding duplicates.
- Steps to Configure:
- Navigate to Configuration > CI Class Manager.
- Select the appropriate CI class (e.g.,
cmdb_ci_computer
). - Review and modify the identifiers to ensure they correctly match the unique properties of your CIs.
- Set up reconciliation rules if needed, under Configuration > Reconciliation.
Advantages:
- Automated: Minimal manual intervention.
- Consistent: Ensures consistency across CIs based on defined rules.
---- >Avoiding Duplicates via Scripting:
In cases where Discovery is not sufficient or you need additional logic, you can use scripting (like a Business Rule) to prevent duplicate entries.
Example Business Rule: You can create a Business Rule on the cmdb_ci
table that checks for duplicates before inserting a new CI.
- Trigger: Before Insert
- Condition: None (applies to all insert operations)
- Script:
(function executeRule(current, previous /*null when async*/) { // Query the cmdb_ci table to check for a duplicate entry var ci = new GlideRecord('cmdb_ci'); ci.addQuery('name', current.name); ci.query(); // If a record with the same name exists, prevent insert if (ci.next()) { gs.addErrorMessage('Duplicate CI detected: A CI with the name "' + current.name + '" already exists.'); current.setAbortAction(true); // Prevent the insert } })(current, previous);
If you found my response helpful, I would greatly appreciate it if you could mark it as "Accepted Solution" and "Helpful."
Your support not only benefits the community but also encourages me to continue assisting. Thank you so much!
Thanks and Regards
Ravi Gaurav | ServiceNow MVP 2025,2024 | ServiceNow Practice Lead | Solution Architect
CGI
M.Tech in Data Science & AI
ï”— YouTube: https://www.youtube.com/@learnservicenowwithravi
ï”— LinkedIn: https://www.linkedin.com/in/ravi-gaurav-a67542aa/