Delete document using Server Script

Hello !!

I am just trying the server script for delete todo.
I tried using this script.

if the description of todo is test that todo deleted after saving.
But I am not geting that what is name in frappe.delete_doc(‘ToDo’, name)

if “test” in doc.description:
frappe.delete_doc(‘ToDo’, name)

Its the document name of the Todo:

You need to change name to

1 Like

I tried that but it gives server error.

TypeError: 'NoneType' object is not callable

Let’s use a better example, and try to delete a customer. The function signature for for delete_doc is something like this:

frappe.delete_doc(<doctype_name>, <document_name>)

In ERPNext, customers are stored in a DocType named “Customer”.
Let’s say we have many customers in our database.
But we want to delete the one with name = “CUST-0005”.

I would write my function exactly like this:

frappe.delete_doc("Customer", "CUST-0005")

That Python function would look like this in SQL:

DELETE FROM `tabCustomer`
WHERE name = 'CUST-0005'

Hopefully this makes more sense now.

There is a DocType in the Frappe App named “ToDo” (representing a list of things ‘to do’). Many of the official Test Scripts and Examples are written about this “ToDo” document. I don’t know why it was chosen. :man_shrugging:


I did this frappe.delete_doc() from a custom button in a custom doctype and call it via
But I get Not permitted error popup. I add the ignore_permissions and/or ignore_missing` but still the same error.
In the browser console returns:

Failed to load resource: the server responded with a status of 403 (FORBIDDEN)

My code:

		function() {{
				"method": "frappe.delete_doc",
				"args": {
					"doctype": 'Subscription Plan',
					"name": frm.doc.subscription_plan,
                    "ignore_permissions": 'True',
                    "ignore_missing": 'False'
                callback: function(r) {
                    if (!r.exc) {
                        frappe.show_alert("Plan has been deleted", 5)                     }

Would you please point me to the right direction?
Thank you.

@rahy did you get any solution to this pleas?

No. Frankly, I haven’t looked at it again.
As a way around I created a “goto” button so I can go to the related document and delete it there.

It seems the code can’t delete the document because it relates/used in other document. e.g: Subscription Plan is used in Subscription document.