duplicate entries with same number
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
We are facing an issue on the xyz table where, due to an unexpected glitch, the number counter was reset to an older value. This went unnoticed for some time, and during this period 50+ records were created with duplicate numbers.
We are looking for guidance on the best approach to handle these duplicate entries, specifically:
- How to safely identify duplicate numbers
- A fix/background script to update the duplicate records with correct, unique auto-generated numbers
- Any recommended preventive measures to avoid this issue in the future
Any help or best‑practice suggestions would be greatly appreciated.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
8 hours ago
for one of our client we got this kind of duplicate but that was human error , someone did records' xml import.
For us count was only 3 , so we deactivated the record for remediation.
For your case , is it production?
If not ,
1. First stop new record creation, till you stop stop duplicate record creation.
for that -
- Navigate to System Definition > Number Maintenance.
- Find the record for your custom table.
- Update the Number field (the next number to be used) to be higher than the highest number currently in your table.
OR click on Show counter related link and increase the count
2. a. I guess ,as count is very less you can manually take backup of those 50 + record like appending "_backUp".
b. You can update it using background /fix script as per your requirement
3. Future protection:
a.
- Navigate to System Definition > Tables.
- Open the record for your desired table.
- In the Columns related list, find the field named Number.
- Open that Dictionary Entry.
- Locate the Default value field under the Default Value tab.
- Enter: javascript:getNextObjNumberPadded();
- Save the record
b. Update system property "glide.itil.assign.number.on.insert" value as 'true'.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
8 hours ago
Thanks for the response @Tanushree Maiti , I need a script to update duplicate records
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
7 hours ago
Hi @Pratiksha Kalas,
You can use the below script in the background script.
var FIELD_NAME = 'number';
var dup = new GlideAggregate(TABLE_NAME);
dup.addAggregate('COUNT', FIELD_NAME);
dup.groupBy(FIELD_NAME);
dup.addHaving('COUNT', '>', 1);
dup.query();
while (dup.next()) {
var duplicateNumber = dup.getValue(FIELD_NAME);
gs.print('Processing duplicate: ' + duplicateNumber);
var gr = new GlideRecord(TABLE_NAME);
gr.addQuery(FIELD_NAME, duplicateNumber);
gr.orderBy('sys_created_on');
gr.query();
var isFirst = true;
while (gr.next()) {
if (isFirst) {
isFirst = false;
continue;
}
var newNumber = new global.NumberManager().getNextObjNumberPadded(TABLE_NAME);
var oldNumber = gr.getValue(FIELD_NAME);
gr.setValue(FIELD_NAME, newNumber);
gr.update();
gs.print('Updated: ' + gr.sys_id +
' | Old: ' + oldNumber +
' -> New: ' + newNumber);
}
}
gs.print('Duplicate fix completed.');
Let me know if this script helps!!!😉
If you find my answer useful, please mark it as Helpful and Correct. 😊
Regards,
Soham Tipnis
ServiceNow Developer || Technical Consultant
LinkedIn: www.linkedin.com/in/sohamtipnis10
