Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

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

Aanchal Mehndi1
Giga Contributor

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

3 REPLIES 3

syedfarhan
Kilo Sage

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


Govind Kumar S1
Kilo Guru

Hi Aanchal ,



Duplicate Records in task table



Hope this helps



Thanks & Regards


Govind Kumar Sharma


sergiu_panaite
ServiceNow Employee
ServiceNow Employee

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