How to Fix duplicate numbers issue using background/Fix script

Ben42
Tera Contributor

Hello Guys,

 

By running the below script in background scripts, we have identified we have 100+ contract records with duplicate record numbers.
And, For the records that share the same number, I need the more recent record to be renumbered to the next available number by using fix script/background script. 

Any help with the code is much appreciated.


Script:
var dupRecords = [];
var gaDupCheck1 = new GlideAggregate('ast_contract');
gaDupCheck1.addAggregate('COUNT','number');
gaDupCheck1.groupBy('number');
gaDupCheck1.addHaving('COUNT', '>', 1);
gaDupCheck1.query();
while (gaDupCheck1.next()) {
dupRecords.push(gaDupCheck1.number.toString() + '\n');
}
gs.print(dupRecords);

 

Thanks,

Ben.