- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-18-2019 11:19 AM
Hi there,
I am creating a fix script that look for duplicates numbers in my custome table 'x_table', for the records that share the same number, the more recent record should be renumbered to the next available number.
so far i have this script:
var dupRecords = [];
var gaDupCheck1 = new GlideAggregate('u_vendor_category');
gaDupCheck1.addQuery('active','true');
gaDupCheck1.addAggregate('COUNT','u_number');
gaDupCheck1.groupBy('u_number');
gaDupCheck1.addHaving('COUNT', '>', 1);
gaDupCheck1.query();
while (gaDupCheck1.next()) {
dupRecords.push(gaDupCheck1.u_number.toString() + '\n');
}
gs.print(dupRecords);
So it will retrun an array with the duplicates number, any help?
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-18-2019 12:18 PM
That's a callback function assigning the record found in the above query or array and assigning it as the "current" record you're adjusting in the function below.
And yes...my script is for background use...
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-18-2019 12:18 PM
That's a callback function assigning the record found in the above query or array and assigning it as the "current" record you're adjusting in the function below.
And yes...my script is for background use...
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-18-2019 01:36 PM
thanks man you are such a life saver 🙂

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-18-2019 01:42 PM
No problem bud. Glad it all worked for you.
Be sure to mark any other reply as Helpful if it was.
Take care!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-18-2019 12:10 PM
Hi,
So loop through the array. Verify the table and field names in the code and try this.
for (i=0;i<dupRecords.length;i++) {
var gr = new GlideRecord("x_table");
gr.addQuery("number",dupRecords[i]);
gr.query();
if(gr.next()) {
gr.number = getNextObjNumberPadded();
gr.update();
}
}
Mark the comment as a correct answer and helpful if it helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-26-2019 08:46 AM
Is there a solution for renumbering duplicates in the knowledge base considering versioning?