Custom Script to disable user

I want to disable user through Custom script.
Please Help!

Thank You

Please Help!

Create a button, and in function add this statement. It should probably work:

Suppose you are in Employee document then in that function, execute this statement.

frappe.db.set_value("User", cur_frm.doc.user_id, "enabled", 0)

Also check that user’s role, make this button visible only for users with Roles like ‘System Manager’ or HR Admin or similar.

This should work. Button examples are available in plenty.

using below script
frappe.db.set_value(“User”,, “enabled”, 0)

that’s worked
Thank you

But also check the user’s role before allowing this button. Don’t allow random people disabling users. I don’t think it will happen this easily but still do it as an extra security measure.

Thank You @root13F
I have already filter the users those are disabled in the System.

No I mean check the role of the person who is logged in. Add a statement to check the logged in user’s role say allow only users with System Manager role or HR Admin role to view this button.

Yes @root13F
I have given to permission for that particular button and allows only one user to press that button.

Thank You

1 Like