- 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-01-2024 09:37 PM
Can any one please help on this.
- 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 02:36 AM - edited 05-02-2024 02:36 AM
@Sujata Lenka Please update your code as follows.
var gr = new GlideRecord('incident');
gr.addQuery('priority','1');
gr.orderBy('sys_created_on');
gr.setLimit(5);
gr.query();
gr.deleteMultiple();
Why was your script not working.
1. setLimit only accepts number value and you provided a string in argument.
2. deleteMultiple in while loop: - Delete multiple doesn't require a loop
Hope this helps
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2024 03:00 AM
Hi @Sujata Lenka ,
There is semicolon missing after gr.deleteMultiple();
try with below code :
var gr = new GlideRecord('incident');
gr.addQuery('priority','1');
gr.orderBy('sys_created_on');
gr.setLimit('5');
gr.query();
while(gr.next())
{
gr.deleteMultiple(); // semicolon was missing
}
Please mark this comment as Correct Answer/Helpful if it helped you.
Regards,
Swathi Sarang