I’m attempting to filter a child table using set_query. The difficulty I’m having is that I want the filter to be the data I’m pulling from another child table.
This pulls the Customer ID number {00001,00002} from the Customer DocType. The result is what I want to use as a filter:
let name = cur_frm.doc.customer
frappe.model.with_doc('Customer', name, function () {
let source_doc = frappe.model.get_doc('Customer', name);
//console.log(source_doc.responsible_persons_list)
$.each(source_doc.responsible_persons_list, function (index, source_row) {
console.log(source_row.customer_id)
});
});
And this is the set_query filter on a different doctype:
// Filter lease_ack child table
frappe.ui.form.on("Lease Agreement", "onload", function(frm) {
frm.set_query("responsible_person","lease_ack", function() {
for ( let i in frm.doc.lease_ack) {
return {
filters: [
['Customer', 'name', 'in', '00001, 00002'],
]
};
}
});
});
I have no idea how insert the results from the first bit of code into the filter variables. Any help would be greatly appreciated, and please limit suggestions to client scripts if possible.
So I’ve managed to create a function that gets the customer account numbers, parses them in the correct format for set_query, however it still doesn’t like it.
The function below returns: '00005,00002'
// Function to return responsible persons based on frm.doc.customer
function getResp(cust) {
var arr = [];
frappe.model.with_doc('Customer', cust, function () {
let source_doc = frappe.model.get_doc('Customer', cust);
$.each(source_doc.responsible_persons_list, function (index, source_row) {
arr.push(source_row.customer_id);
let newarr = "'" + arr.join() + "'"
});
});
}
The string from above is passed to the filters array:
// Filter lease_ack child table
frappe.ui.form.on("Lease Agreement", "onload", function (frm) {
frm.set_query("responsible_person", "lease_ack", function () {
let resp = getResp(frm.doc.customer);
for (let i in frm.doc.lease_ack) {
return {
filters: [
['Customer', 'name', 'in', resp],
]
};
}
});
});
The filtered result is empty. Is there a way to pass this variable into the filter?