Cron job to routinely delete all documents of a DOCTYPE

Hello ERPNext users and developers,
I would like to write some kind of cron job to search for and delete all documents of a DOCTYPE.
Please point me in the right direction.

The use case is some kind of suggestion box that would send email alerts on save then delete itself automatically

This is what I have done so far, let’s assume the doctype I am trying to delete is “Customer”

You cannot run frappe.delete command from server script. Trust me I already tried. This is the error you will get:

Traceback (most recent call last):
File “apps/frappe/frappe/core/doctype/scheduled_job_type/scheduled_job_type.py”, line 79, in execute
frappe.get_doc(‘Server Script’, script_name).execute_scheduled_method()
File “apps/frappe/frappe/core/doctype/server_script/server_script.py”, line 105, in execute_scheduled_method
safe_exec(self.script)
File “apps/frappe/frappe/utils/safe_exec.py”, line 55, in safe_exec
exec(compile_restricted(script), exec_globals, _locals) # pylint: disable=exec-used
File “”, line 1, in
File “apps/frappe/frappe/utils/safe_exec.py”, line 191, in read_sql
raise frappe.PermissionError(‘Only SELECT SQL allowed in scripting’)
frappe.exceptions.PermissionError: Only SELECT SQL allowed in scripting

You can only call data using frappe.db commands in server script but not modify data directly. You have to write the script server side for it to work.

Thank you for the response. Unfortunately, I am not a software developer and really don’t know how to go about this. If you can share a code or a how-to then I would be very appreciative!!!

Here is the solution I adopted.

  1. I created a new app, then installed it to my site.
  2. I edited the hooks.py file in my new site to enable the scheduler feature.
  3. I put the command "frappe.db.sql(“DELETE FROM tabDocName”).
  4. I restarted bench.