In purchase order item table, there is field project and budget fields. First i select project then budget. When i click on budget then link records show filter based on project field selection.
Please check the syntax, now you have to set it according to the scenario. If onload not worked then use refresh.
frappe.ui.form.on("Purchase Order", {
onload: function (frm) {
frm.set_query("budget", "items", function (doc, cdt, cdn) {
let row = locals[cdt][cdn];
return {
"filters": {
"project": row.project,
},
};
});
},
});
Please check out this code
frappe.ui.form.on("Purchase Order", {
onload: function (frm) {
frm.fields_dict.items.grid.get_field('budget').get_query = function(doc, cdt, cdn) {
var row = locals[cdt][cdn];
if (row.project) {
return {
query: "#path.fetch_projectwise_budget_list",
filters: { "project": row.project}
};
}
};
}
})
Python Function
@frappe.whitelist()
def fetch_projectwise_budget_list(doctype, txt, searchfield, start, page_len, filters):
query = """
SELECT
bu.name as title
FROM
`tabBudget` as bu
WHERE
bu.project= %(project)s
and bu.name like %(txt)s
""".format(project = filters.get('project')
values = frappe.db.sql(query.format(
key=searchfield, value="%{0}%".format(txt)
),
{
'txt': "%{0}%".format(txt),
'start': start,
'page_len': page_len
})
return values
above both solutions not working.
Budget has a project field or not? share the screenshot and where you want.
There is no budget field in project.
So, how do we set the filter?
You mentioned to first set the project filter and then select the budget, expecting the budget to display based on the project filter. However, since the budget does not have a project field, it doesn’t make sense to set the filter in this way.