I have a query below to get users that has specific role
select tu.name from `tabUser` tu, `tabHas Role` thr
where thr.parent = tu.name
and thr.role like "%PO Approver%";
I want to apply this query to a custom client/server script.
so far what I can do is filtering the user list based on columns in the User table. but on this case I need to join between tabUser and tabHas Role, that’s where I need help.
I’m not a developer so I don’t know to achieve that with a client/server script.
For example, you can create a Custom Link field named “User” in a Sales Order.
Write a client script for the Custom Link field. To do this, go to the Custom Script application and create a new script. Select the applicable doctype, in this case, Sales Order, and add the following code to filter the users based on their roles:
the result throws an error message on my PO when I select the field.
pymysql.err.OperationalError: (1054, “Unknown column ‘tabUser.roles’ in ‘where clause’”)
I believe this happens because “roles” does not exist in the tabUser table, thus needs a join to tabHas Role
Is it possible to join the table to tabHas Role to get the assigned role?
Oh, and is there a way to use “like” operator so I don’t have to put every role?