How to filter Document List View based on User ID

Hello,

In a single doctype, I want to give record level permission by user id or a field value. So that different users will access different records. Only Administrator will access all records. Role Permission Manager and/or User Permission is not enough to do this. Because, it will be on same DocType but different records.

Can anyone help me and guide how to write py or js file.

TIA.

1 Like

Hi, @mijan1373
There is an option available in Role Permission Manager.
First set the same Role for User in User List Doctype.
enable Only if Creator and Set User Permission. for the same Doctype and Role.
this will restrict users to view records created by other users.

Thanks. I am aware of it. But, I have different role like units, document creator, approver etc. If I check “Only if Creator”, that works at creator role, but not at approver role. What exactly I want that documents created by Unit1 should not be visible to the Users of Unit2.

Hope it is clarified.

@mijan1373 if you want to do this manually , you can do a “user permission” , chose user , doctype and the value of the one he allowed to see

@bahaou in that case I have to it one by one. I will prefer a permission control like filter i.e. a mandetory/permanent filter using js or py.

Is there anyway to filter data in the py file and List only returned records/data.

My problem is similar to Role Restriction

@mijan1373 humm try this scenario . add some kinda grouping to the doctype , like branches or departments . and then add the branch permission to the user with user permission. this way he can only see doctypes that are linked to that branch .
this is how I did it to show only sales invoices linked to a company

@bahaou
Done it and partially working.

I have Agency > Ministry > Sector and three DocType corresponding to these three.
These are Link Field to Project DocType. I have created permissions for “Agency Officer” and “Agency Head”(both are user) and allowing Agency doctype, applicable to Project doctype.

Now, when I login as “Agency Officer”, the Project list are projects which belongs to my agency, but when I am trying to click on Agency, Ministry or Sector link field, system throw message “Insufficient Permission to Agency” (Ministry/Sector). However, if I create a new Project, the Agency gets correct value, but I can’t click on any link field. They throws above mentioned message.

try giving the permissions . the filter still works even with all permissions

Try these:

Hooks modify-list-query
Hooks document-permissions

@bahaou
Finally it works. Thank you very much.

The solution I did is as follows:

  1. Added Agency, Ministry and Division as link fields. Data for Division fetched on Agency and Ministry fetched on Division.
  2. Giver User Permission to Agency User on Agency doctype with value of his/her Agency only.
  3. Giver User Permission to Division User on Division doctype with value of his/her Division only.
  4. Giver User Permission to Ministry User on Ministry doctype with value of his/her Ministry only.

As a result users are able to see only there own entity records.

Thanks again.

@amadhaji
Thank you bro