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.

5 REPLIES 5

Ben42
Tera Contributor

Hello Basheer,

 

Thank you for the response. I tried to run your script in the background script but looks like sys ids are not showing up but only record numbers are showing up. and may be that would be the reason that duplicate record numbers are not getting updated.

 

why sys ids are not displaying? any idea?

Thanks,

Rocky.