ERPNext.com Frappe Cloud Support Partners Foundation

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: doc.name

You need to change name to doc.name

1 Like

I tried that but it gives server error.

TypeError: 'NoneType' object is not callable
@abhishekbalam

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:

Hi,

I did this frappe.delete_doc() from a custom button in a custom doctype and call it via frappe.call
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() {
			frappe.call({
				"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.