Trying to schedule a delete job

Ken Berger
Giga Guru

Hi folks,

 

I created a delete job in System Data management => Delete Jobs, but it keeps stopping after a few hours without deleting all the records (apparently due to transaction quotas).  I learned that you can use scheduled jobs for this but I cannot see a way to set this delete job that I created to a recurring schedule (can only schedule it to run once in the future).

 

What would be the best way to accomplish this as a scheduled job?

 

Thanks,

Ken

1 ACCEPTED SOLUTION

Sonam_Tiwari
Kilo Sage

An alternate option will to be use Table cleaners.

 

How to use Table Cleaner to remove unwanted data - Support and Troubleshooting (servicenow.com)

 

 

Consider indicating the response as helpful and marking it as correct if it meets your needs.

View solution in original post

5 REPLIES 5

Sonam_Tiwari
Kilo Sage

An alternate option will to be use Table cleaners.

 

How to use Table Cleaner to remove unwanted data - Support and Troubleshooting (servicenow.com)

 

 

Consider indicating the response as helpful and marking it as correct if it meets your needs.

Thanks sonamtiwari,

 

That was the most stable and quickest way with cascade deletes.  It didn't seem to be working quickly but after a few days, the table went from over 20,000 to 30 records.

 

Best regards,

Ken

Gary-NZ
Tera Contributor

Probably the best way is to schedule the delete of each record like this:-

 

var so = new ScheduleOnce();
so.script = "//Your script as a string goes here";
so.schedule();

More details from this great Blog Post
CALL A SERVICENOW SCRIPT ASYNCHRONOUSLY WITH SCHEDULEONCE API

This creates one schedule task and helps when the delete runs several business rules etc.


With any delete job, please test in DEV.

Hi Gary-NZ,

 

Thanks for the reply.  When you do it this way, does it also cascade delete records in related tables?  I have this script:

 var gr = new GlideRecord('cmdb_ci_computer');
  var strQuery = 'sys_class_name=cmdb_ci_computer^osNOT LIKEserver^osNOT LIKElinux^osNOT LIKEstandard^osNOT LIKEdatacenter^nameNOT LIKEhq';
  gr.addEncodedQuery(strQuery);
  gr.query();
  gr.deleteMultiple();

 

Thanks,

Ken