Deleting all the record in incident table even added the limit

Sujata Lenka
Tera Contributor

I am using a code in back ground script to delete 5 p1 record , but it deleting all the incident records in incident table. 

 

script is as below, please help in it.

var gr = new GlideRecord('incident');
gr.addQuery('priority','1');
gr.orderBy('sys_created_on');
gr.setLimit('5');
gr.query();
while(gr.next())
{

gr.deleteMultiple()
}

1 ACCEPTED SOLUTION

Amitoj Wadhera
Kilo Sage

Hello @Sujata Lenka ,

 

 

Please try the below script:

 

 

var gr = new GlideRecord('incident');
gr.addQuery('priority','1');
gr.orderBy('sys_created_on');
gr.setLimit(5);
gr.query();
while(gr.next())
{
gr.deleteRecord();
}

 

If you find my response helpful, please consider marking it as the 'Accepted Solution' and giving it a 'Helpful' rating. Your feedback not only supports the community but also encourages me to continue providing valuable assistance.

 

Regards,

Amitoj

View solution in original post

5 REPLIES 5

Sandeep Rajput
Tera Patron
Tera Patron

@Sujata Lenka You don't need while loop to execute delete the records, simply use gr.deleteMultiple(); The selected answer is not a performance efficient answer.