Fields visibility for owner only


I have a case where I would like my employee to see all fields of LeaveApplication only when they are owners of such document. If they are not owning particular LeaveApplication, they should still see all documents of this type but only some of the fields.

I was trying to set this up using fields permission levels, but I could not get it working. If is assign ie level 1 to employee role which has access to LeaveApplication with “If owner” set, and another role with just level 0, it will grant access to all fields to all documents, not only to those where user is owner.

Is this is possible to achieve?

field level permission will not hide the field you will need to write the custom script to hide the field if the documents is opened by the user other than the user.

You can use the frm.toggle_display('fieldname', true or false) method to hide and unhide the field.

e.g. frm.toggle_display("fieldname", frappe.session.user == frm.doc.owner)

Thanks for reply! Two questions tho:

  1. Where do I add this script?
  2. this would hide those fileds from all non-owner, in my case ie. I have HR users which should see all fields. What I want to achieve is that Employees see each others LeaveApplications, but only some fields. LeaveApplication owner see all fields, other roles may see all fields as well.

add the custom script for the Document, just search the Custom Script in Awesome Bar.

You can check the role as well as the document owner use frappe.user_roles to get the role of the logged in user


frm.toggle_display(“fieldname”, frm.doc.owner == frappe.session.user || frappe.has_common(frappe.user_roles, [“HR user”, “HR Manager”]))

1 Like


One more question, I’m using version 8.1x and when I try to use “frm” it throws error: ReferenceError: frm is not defined.

Ok, I’ve managed to make it work! Thanks for help!