HR employee left should disable userid

Small customization on HR when employee left usually no communication to Admin to disable userid (if added on his form).

System should check if status left and userid => disable.

You can use below custom script in Employee

validate:function(frm){
    if(frm.doc.status == 'Left'){
	frappe.call({
	method: "frappe.client.set_value",
	args: {
		doctype: "User",
		name: frm.doc.user_id,
		fieldname: "enabled",
		value: 0,
	},
	freeze: true,
	callback:(r){
		frappe.msgprint(__("User has been Disable from Access"));
	}
});

	}
1 Like

Thanks for the reply but my point here was to make it standard or as a option to HR…

We have done this but I believe many other non-developers require as a standard.

1 Like

I think you should raise a github issue or make pull request with this functionality

1 Like

Added a Github Issue for this:

https://github.com/frappe/erpnext/issues/25019

1 Like

Thanks providing this script. Just to point out that there was some syntax that was not in the script which made it not to work for me when placed in the client script window of my instance. After few debugs the below script worked fine for me:

frappe.ui.form.on(‘YourDocType’, {
validate: function(frm) {
if (frm.doc.status === ‘Left’) {
frappe.call({
method: “frappe.client.set_value”,
args: {
doctype: “User”,
name: frm.doc.user_id,
fieldname: “enabled”,
value: 0,
},
freeze: true,
callback: function(r) {
if (!r.exc) {
frappe.msgprint((“User has been disabled from access.”));
} else {
frappe.msgprint(
(“Error occurred while disabling the user.”));
}
}
});
}
}
});