- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-02-2015 01:45 PM
Hi friends,
I was wanting to delete some 23,387 records from the requested item table based on a certain criteria as below. I have my code as seen below but please help me with how I can tweek the code more so that I can ask it to delete a few hundred or 1000 records at a time as if i just run deleteMultiple() it hangs.
the code:
var delRec = new GlideRecord("sc_req_item");
var queryRec = (("requestISEMPTY") && ("request.u_requested_byISEMPTY") && ("request.requested_forISEMPTY"));
delRec.addEncodedQuery(queryRec);
delRec.deleteMultiple();
Please assist.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-02-2015 02:46 PM
you could add this just before the deleteMultiple
delRec.setLimit(1000);
To limit to a thousand... (or however many you wish)
RM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-09-2017 06:46 AM
Thansk Berny. This got me started. Exactly what I needed. You'll most likely need to tweak the particulars for your scenario (copy/paste will probably not work).
For anyone who likes setpped-out instructions like me, here's what I did:
- Navigate to System Definition > Scheduled Jobs
- New > "Automatically run a script of your choosing"
- Name: [A name that you'll recognize later]
Active: true
Run: Once
Starting: (blank)
Conditional: false
Run this script:
var gr = new GlideRecord('table'); //Replace 'table' with the table in which you want to delete the records
gr.addQuery(("state=1")&&("sys_created_on<javascript:gs.daysAgoStart(1)")); //In my case want to delete items w/ 'New' state (value of 1) that were created before yesterday (originally I only wanted to delete records created before today so the argument sent in gs.daysAgoStart() was '0' instead of '1').
gr.deleteMultiple(); //Delete the records that were found.
- Save the form then click the 'Execute Now' button to run it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-09-2017 07:11 AM
You're welcome Aaron. I'm glad it was helpful!
Thanks,
Berny