How to prevent Edit and/or Delete on DocType?+

I have a “status” doc_field… I need to block edit and/or delete depends of the “status” value…

Where is the better approach and how can I do that?


1 Like

Change role permission for the particular user.

Hello @rk_root I do not want to prevent edit/delete from user… lI want like these: if status = ‘A’ doesn’t edit/delete… just need to check the status, depend of the value of the status, user can edit/delete .

Have you tried hook? by creating a method and hook it with on_trash and on_update or on_change, check if status cannot be edited or deleted, throw an error.

I read the link, but, I do not understand how to apply these to my issue…

Could you, please, give me a example how to do that?


Here’s a question like yours with a response that may help? Hooks events script

Here’s hook example when delete Contact

Method example, update_issue (

When event hook called, it passes two parameters. Doctype object , method. Like example above, it passed contact doctype object and event (method) as string “on_trash”.

Regarding your issue:
let’s say your doctype is Contact and you want to prevent user to edit or delete when status == “ready”

Assuming you have custom app, your hook would be:

		"on_update": "",
        "on_change": "",
        "on_trash": "",

Your method would be: (

class Contact(Document):

def check_before_edit_delete(doc, method):
    if(doc.status == "ready"):
        frappe.throw(_("This record is not allow to edit or delete"))
1 Like