HR employee left should disable userid

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.”));
}
}
});
}
}
});