- 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
 
			
    
	
		
		
		‎12-02-2015
	
		
		02:37 PM
	
	
	
	
	
	
	
	
	
	
	
	
	
	
 - last edited on 
    
	
		
		
		‎09-16-2023
	
		
		11:36 PM
	
	
	
	
	
	
	
	
	
	
	
	
	
	
 by 
				
		
		
			ServiceNow 
		
		
		
		
		
		
		
		
	
			
		
Priya,
I've used a similar query to delete 50k+ records from a table before (although my encoded query looked different). The delete just takes a while because it cascade deletes. I think you'll have to be patient with it. There are other solutions like gs.sql('TRUNCATE TABLE .... but that can leave you with a much bigger mess than what you have. This article explains in further detail.
- 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
 
‎12-02-2015 09:37 PM
Hi Priya,
Probably when you thought the query was "hanging" it was busy deleting records.
Have you checked with getRowCount(); to see how many rows are still awaiting deletion?
Maybe you have actually succeeded?
Best Regards
Tony
- Mark as New
 - Bookmark
 - Subscribe
 - Mute
 - Subscribe to RSS Feed
 - Permalink
 - Report Inappropriate Content
 
‎12-02-2015 09:51 PM
Hi Priya,
I would suggest you try to delete the records using an on demand schedule job. That way the process would not be associated to a UI session and would run in the background without interruptions.
Thanks,
Berny
