Hi,
I want to fetch the list of all employees in ‘Select Field Type’
just like Doctype & Roles are placed in Role Permission Manager’s Page,
Yes there is a reason, actually i am creating the form for IT Department,
& IT Manager will have to select the Employee Name is my Custom Doctype,
If i uses the Link, then i’ve to give the read access of All Employees to the IT Manager & i don’t want to give access of all employees data to the IT Manager because Employee Data is confidential.
Hope you got my case.
I had the same issue, and I have solved it by using set_query and set my own query for it as follow:
JS code
frm.set_query("employee", function() {
return {
query: "path.get_employee",
filters: {
employee: frm.doc.employee
}
};
});
Py Code
@frappe.whitelist()
def get_employee(doctype, txt, searchfield, start, page_len, filters):
emp = frappe.db.sql("select name,employee_name from `tabEmployee`")
return emp
@OmarJaber thanks for you help, let me try.
P.S. The employee field should be linked to Employee, and this query will override the linking record
i’ve tried but its not working, & giving the following error :
Traceback (most recent call last):
File "/opt/bitnami/apps/erpnext/htdocs/frappe-bench/apps/frappe/frappe/app.py", line 62, in application
response = frappe.handler.handle()
File "/opt/bitnami/apps/erpnext/htdocs/frappe-bench/apps/frappe/frappe/handler.py", line 22, in handle
data = execute_cmd(cmd)
File "/opt/bitnami/apps/erpnext/htdocs/frappe-bench/apps/frappe/frappe/handler.py", line 53, in execute_cmd
return frappe.call(method, **frappe.form_dict)
File "/opt/bitnami/apps/erpnext/htdocs/frappe-bench/apps/frappe/frappe/__init__.py", line 939, in call
return fn(*args, **newargs)
File "/opt/bitnami/apps/erpnext/htdocs/frappe-bench/apps/frappe/frappe/desk/search.py", line 14, in search_link
search_widget(doctype, txt, query, searchfield=searchfield, page_length=page_length, filters=filters)
File "/opt/bitnami/apps/erpnext/htdocs/frappe-bench/apps/frappe/frappe/desk/search.py", line 35, in search_widget
searchfield, start, page_length, filters, as_dict=as_dict)
File "/opt/bitnami/apps/erpnext/htdocs/frappe-bench/apps/frappe/frappe/__init__.py", line 924, in call
fn = get_attr(fn)
File "/opt/bitnami/apps/erpnext/htdocs/frappe-bench/apps/frappe/frappe/__init__.py", line 919, in get_attr
return getattr(get_module(modulename), methodname)
AttributeError: 'module' object has no attribute 'get_employee'
PY Code :
class IMS(Document):
pass
@frappe.whitelist()
def get_employee(doctype, txt, searchfield, start, page_len, filters):
emp = frappe.db.sql("select name,employee_name from `tabEmployee`")
return emp
JS Code :
frappe.ui.form.on('IMS', {
refresh: function(frm) {
frm.set_query("employee_id", function() {
return {
query: "erpnext.hr.doctype.ims.ims.get_employee",
filters: {
employee_id: frm.doc.employee_id
}
};
});
}
});
I am wondering that why its not working for me, i’ve the ditto same code and same field_name linked to Employee, but no luck here ![]()
maybe i am doing mistake somewhere.
@OmarJaber Thank you so much, its working after restarting the server.





