I created a new doctype named “sales target” and its js is given below
I wrote this with chat gpt.
// Copyright (c) 2024, Frappe Technologies Pvt. Ltd. and contributors
// For license information, please see license.txt
frappe.ui.form.on(‘Sales Target’, {
onload: function(frm) {
// Filter the Sales Officer field to show only users with the “Sales Officer” role
frm.set_query(‘sales_officer’, function() {
return {
filters: {
role: “Sales Officer”
},
query: function() {
return frappe.call({
method: “payments.api.get_users_by_role”,
args: {
role: “Sales Officer”
},
async: false
}).then((response) => {
return response.message || ;
});
}
};
});
// Filter the Manager field to show only users with the "Manager" role
frm.set_query('manager', function() {
return {
filters: {
role: "Manager"
},
query: function() {
return frappe.call({
method: "payments.api.get_users_by_role",
args: {
role: "Manager"
},
async: false
}).then((response) => {
return response.message || [];
});
}
};
});
}
});
and this is my custom app named " payments " the payments > api.py file is given below
import frappe
@frappe.whitelist()
def get_users_by_role(role=None):
if not role:
return
# Custom SQL query to get users with the specified role
query = """
SELECT u.name, u.email
FROM `tabUser` u
JOIN `tabUserRole` ur ON u.name = ur.parent
WHERE ur.role = %s
"""
users = frappe.db.sql(query, role, as_dict=True)
return users
and when i open the sales target doctype in my ERPNext this 2 error will pop up
how can i solve this issue ?