Getting the duplicate entry

Anna_Servicenow
Tera Guru

We a custom table u_pets, when certain conditions match the new entry will be treated as duplicate. Now, how change the status of all records created except the first one to duplicate. Below is my script that is returning all record matching condition.

 

var gr = new GlideRecord('u_pets');
    gr.addEncodedQuery('case_id=f4fe7db01b439585d8cd4bcb01^amount=100');
 gr.addQuery('sys_created_on', '>', gs.daysAgo(30));
  gr.orderBy('sys_created_on');
    gr.query();
while (gr.next()) {
       gs.print(gr.number);
     gr.state=8;
         }
 
5 REPLIES 5

Voona Rohila
Kilo Patron
Kilo Patron

Hi @Anna_Servicenow 

Try this 

var gr = new GlideRecord('u_pets');
gr.addEncodedQuery('case_id=f4fe7db01b439585d8cd4bcb01^amount=100');
gr.addQuery('sys_created_on', '>', gs.daysAgo(30));
gr.orderBy('sys_created_on');
gr.query();
gr.next();//Skip the first record
while (gr.next()) {
    gs.print(gr.number);
    gr.state=8;
   //gr.update();
}

Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP

Anna_Servicenow
Tera Guru

This is excluding first record but now the gr.state = 8 update is not happening. Is this related?

Uncomment the gr.update() line and run the code.

 


Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP

Did you get chance to check my answer?

 

If your issue is resolved now.

 

If yes, can you please mark appropriate response as correct for others who may have a similar question in the future and close this unresolved thread.

 

If not, please let us know if you need any other help


Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP