- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-06-2016 06:45 AM
Hi all,
I have modified this script I found to try delete multiple records but so far it fails.
I am going to be using the scripts background function as it is just a 1 time event. The records are before the 1st of April so I added an encoded query. Can anyone see where I am going wrong as I can't sit and delete all these records manually.
var gr = new GlideRecord('pa_scores');
gr.addQuery('breakdown','=', 'Model Category');
gr.addEncocdedQuery(sys_created_on<=javascript:gs.dateGenerate('2016-03-31','23:59:59'));
gr.query();
while (gr.next()) {
//Delete each record in the query result set
gr.deleteRecord();
}
Thanks,
Lucien
Solved! Go to Solution.
- Labels:
-
Performance Analytics
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-07-2016 03:02 AM
Thanks all for your help and with a bit of changes with your guidance I got it working. Below is what I have used.
var gr = new GlideRecord('pa_scores');
gr.addQuery('breakdown.name','=', 'Model Category'); // Pradeep Sharma update
gr.addEncodedQuery('sys_created_on<=' + gs.dateGenerate('2016-03-31','23:59:59')); // Chuck Tomasi update
gr.query();
while (gr.next()) {
gr.deleteMultiple(); // Ken and Santosh update
}
It still took time to delete these records (Dev instance 1st) but now that I know it works I can do this in production.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-22-2022 03:09 AM
I have a question here what if i need to skip the records returned from the encoded query and delete the rest of the records ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-26-2024 12:14 PM
Hi, just as a heads up, you actually don't need to put a gr.____Multiple() into a loop. deleteMultiple() and updateMultiple() both operate on the query itself, so the code should look like this:
var gr = new GlideRecord('pa_scores');
gr.addQuery('breakdown.name','=', 'Model Category');
gr.addEncodedQuery('sys_created_on<=' + gs.dateGenerate('2016-03-31','23:59:59'));
gr.query();
gr.deleteMultiple();
Effectively what your version of the code does is enter the while loop, run the delete on the query, check the gr.next() which will return false because all of those records were deleted, and then exit.
Not the biggest difference, but just letting you know you can clean up a couple instructions.
Hope this helps!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-24-2022 06:53 AM
//Find all inactive incidents and delete them all at once
var gr = new GlideRecord('incident');
gr.addQuery('active', false);
gr.deleteMultiple(); //Deletes all records in the record set according to Digital Marketing Agency requirements
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-25-2023 01:34 PM
Is there any way to show the results of the query before deleting?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-05-2023 08:03 PM
Here is what I used to clear all records from Scope Application where we need to clear the records to import clean versions of the fields.
var gr = new GlideRecord('Table Name');
// Create a GlideDateTime object for '2023-09-04 23:59:59'
var dateThreshold = new GlideDateTime('2023-09-04 23:59:59');
gr.addQuery('sys_created_on', '>=', dateThreshold);
gr.query();
while (gr.next()) {
gs.info(gr.sys_id);
// gr.deleteRecord(); // You can uncomment this line to delete the records if needed.
}