How to hide list depends on user roles, field value

Can anyone help me,
How to set list view for asset movement doctype, depends on user roles,
Field value, suppose doc.purpose is Issue, then employees can see only that document?

Hi @Shubham_Prabhat1:

Create a server script, for Asset Movement doctype, type Permission Query.
Enable it.

user = frappe.get_doc("User", frappe.user)
user_roles = [r.role for r in user.roles]
is_employee = "Employee" in user_roles

if is_employee:
    conditions = '''purpose = "Issue"'''

Other approach would be using hooks on your custom app …
Hope this helps.

1 Like


Did not work using above code,

As you can see in the 2nd screenshot, still showing the receipt documents for Employee role

But, I don’t want to see others documents except Purpose =Issue

Hi @Shubham_Prabhat1:

Some things to check:

  • Seems you have some permissions applied to the user. Maybe are related?

  • Check if the script is running.

frappe.msgprint("Hello!")
user = frappe.get_doc("User", frappe.user)
user_roles = [r.role for r in user.roles]
is_employee = "Employee" in user_roles

if is_employee:
    frappe.msgprint("Elvis is alive")
    conditions = '''purpose = "Issue"'''

If you see “Hello”, the script is running …
If you don’t see Elvis … maybe your logged user has not Employee role?

Hope this helps.