Replace the duplicate number
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2024 03:58 AM
Hi All,
I am trying to replace the duplicate number in the table and write down the below script
var dupRecords = [];
var gaDupCheck1 = new GlideAggregate('cmdb_ci_business_app');
gaDupCheck1.addQuery('active','true');
gaDupCheck1.addAggregate('COUNT', 'number');
gaDupCheck1.groupBy('number');
gaDupCheck1.addHaving('COUNT', '>', 1);
gaDupCheck1.query();
while (gaDupCheck1.next()) {
dupRecords.push(gaDupCheck1.number.toString());
}
gs.print(dupRecords);
fixDuplicates(dupRecords);
function fixDuplicates(dupRecords) {
var gr = new GlideRecord('cmdb_ci_business_app');
gr.addQuery('number', dupRecords);
gr.orderByDesc('sys_created_on');
gr.query();
while (gr.next()) {
var nm = new NumberManager('cmdb_ci_business_app');
gr.number = nm.getNextObjNumberPadded();
//gr.update();
}
gs.print(gr.number);
}
But when i executed this script, it will replace both the duplicate number with the next available counter where I just need to update only one duplicate number record.
Can someone check this and provide the solution?
Thanks!
Vaibhav J
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2024 05:03 AM
what debugging have you done so far?
few changes
gr.addQuery('number', 'IN' , dupRecords);
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2024 05:20 AM
Hi Ankur,
This solution is not working and still changing both the numbers.
Thanks!
Vaibhav J