Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
var DuplicateCIDetector = Class.create();
DuplicateCIDetector.prototype = {
initialize: function() {},

findDuplicates: function(ciName, serialNumber, assetTag, sysId) {
var duplicates = [];
var gr = new GlideRecord('cmdb_ci');
gr.addQuery('active', true);

// Basic name match (case-insensitive)
if (ciName) {
gr.addQuery('name', 'LIKE', ciName);
}

// Optional matching by serial or asset tag
if (serialNumber) {
gr.addOrCondition('serial_number', serialNumber);
}
if (assetTag) {
gr.addOrCondition('asset_tag', assetTag);
}

if (sysId)
gr.addQuery('sys_id', '!=', sysId); // ignore current record

gr.query();
while (gr.next()) {
duplicates.push({
name: gr.getValue('name'),
serial_number: gr.getValue('serial_number'),
asset_tag: gr.getValue('asset_tag'),
sys_id: gr.getUniqueValue()
});
}

return duplicates;
},

type: 'DuplicateCIDetector'
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Duplicate CIs (Configuration Items) in the CMDB cause data redundancy, reporting errors, and incorrect impact analysis.
This project automatically detects potential duplicate CIs during record creation or update, using partial string matching and fuzzy comparison on fields like Name, Serial Number, or Asset Tag.

It can warn the user, flag duplicates, or even prevent save depending on configuration.

πŸš€ Features

Detects duplicate Configuration Items on insert or update

Matches based on configurable fields (e.g., name, serial_number, asset_tag)

Uses partial/fuzzy matching (e.g., "Laptop123" β‰ˆ "Laptop-123")

Optionally prevents saving duplicate entries

Works on both platform UI and Service Portal

Extendable for custom CI classes (cmdb_ci_computer, cmdb_ci_server, etc.)
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
(function executeRule(current, previous /*null when async*/) {
var detector = new DuplicateCIDetector();
var duplicates = detector.findDuplicates(
current.name,
current.serial_number,
current.asset_tag,
current.sys_id
);

if (duplicates.length > 0) {
var message = 'Potential duplicate CIs detected:\n';
for (var i = 0; i < duplicates.length; i++) {
message += '- ' + duplicates[i].name + ' (Serial: ' + duplicates[i].serial_number + ')\n';
}

gs.addErrorMessage(message);
current.setAbortAction(true); // stop record save
}
})(current, previous);
Loading