How can I apply a filter on a list programmatically using logged in User attributes/roles?

I have added a custom field, “region” on to the User doctype and the same field is available on the sales order doctype.

I want the Sales Order list to be filtered by the region field by default if the currently logged in user has a region set on their record.

e.g If User region is Kolkata, I want the user to only see sales orders with same region, Kolkata.

Create Region as a Doctype and provide User Permission for Region=Kolkata


Thanks for the reply @Manan_Shah, can you please explain in more detail?

PS: I already have a Region DocType

Once you have the Region Doctype. I am assuming you are setting it on Sales Order through some logic.
Using User Permissions, you can restrict users to a particular Region.

You can refer to this video, where I have done something similar for Restricting Salespersons to see SOs only for their respective Customers


Thanks, let me check that video

if your requirement is not to restrict the user access to sales order by his assigned region, in other word your use case is to auto filter the sales order by region in user master when user goes to sales order list view, then please consider setting the route_options like below in the list view’s onload event(You can try in the client script):

frappe.listview_settings[‘Sales Order’] = {
onload: function(listview){
frappe.route_options = {‘region’:‘allowed region from user master’};

1 Like