Get a first look at what's coming. The Developer Passport Australia Release Preview kicks off March 12. Dive in! 

Need to set the Number field Unique and delete all duplicate records

SNOW46
Tera Contributor

Hi All,

I want to set the Number field for Incident as Unique, But when I am trying to set it as Unique, its showing an error as "New Unique index skipped: Requested columns (number) on table (task) contain duplicate values. You must remove duplicate values and then try again." 

Can anyone let me know how to fix this issue. I want to delete all duplicate Incident Records but I am not finding any possibilities or tricks to fix this.

 

Thanks,

SNOW@Das 

1 REPLY 1

rad2
Mega Sage

You can run a background script and delete the duplicates -

https://community.servicenow.com/community?id=community_question&sys_id=fa709ee3dbec9fc87b337a9e0f961991

 

var gr = new GlideRecord('u_incident');
gr.groupBy('number');
gr.query();
while(gr.next()){
  var inc = new GlideRecord('u_incident');
  inc.addQuery('number', gr.number);
  inc.query();
  inc.next();
  while(inc.next()){
   inc.deleteRecord();
  }
}