Duplicates Numbers

Mr Bow
Kilo Expert

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?

1 ACCEPTED SOLUTION

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!

View solution in original post

9 REPLIES 9

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!

thanks man you are such a life saver 🙂

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!

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.

BryanS413339635
Tera Guru

Is there a solution for renumbering duplicates in the knowledge base considering versioning?