- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2024 05:47 AM
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()
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2024 01:45 AM - edited 05-02-2024 02:38 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2024 04:35 AM
@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.