Need to correct numbering of records, there are duplicate number records in a table.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-28-2015 02:42 AM
I need to renumber records as there are a duplicate number records in a table.
can somebody help me with background script or other suggestions.
Eg: there are two records with same number: CTI0001140
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-28-2015 02:55 AM
Hi AAnchal,
You can try this BR
var curNum = current.number + '';
if(curNum) {
var recordClass = current.getRecordClassName();
var gr = new GlideRecord(recordClass);
gr.addQuery('number', curNum);
gr.query();
if(gr.getRowCount() > 0) {
var newNum = getNextObjNumberPadded();
gs.addInfoMessage("The number " + current.number + " was already used by another " +
recordClass + ". The " + recordClass + " number has been changed to " + newNum);
current.number = newNum;
}
}
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-28-2015 02:58 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-28-2015 03:05 AM
You can try:
var count = new GlideAggregate('task');
count.addAggregate('COUNT', 'number');
count.groupBy('number');
count.addHaving('COUNT', '>', 1);
count.query();
while (count.next()) {
gs.log("The task " + count.number + " has duplicates" );
}
Regards,
Sergiu