Ryan1
March 20, 2024, 5:31am
1
Filtering logic does not work in listview inside Doctype for child table but when I expand the row and then it works correctly. My code for custom script is in below:
frappe.ui.form.on('Sales Invoice Item', 'item_code', function(frm,cdt,cdn) {
var d = locals[cdt][cdn];
frappe.call({
method: "erpnext.stock.doctype.item.item.itemwise_uom",
args:{item:d.item_code},
callback: function(r) {
console.log(r);
const uoms =[];
uoms.pop();
for (var i = 0;i<r.message.length;i++){
uoms.push(r.message[i].uom);
}
console.log(uoms);
frm.set_query('uom', 'items', function(doc, cdt, cdn) {
return {
filters: [
['name','in', uoms]
]
}
});
}
});
});
NCP
March 20, 2024, 5:50am
2
Hi @Ryan1 ,
Try it.
frappe.ui.form.on("Sales Invoice", {
refresh: function(frm, cdt, cdn) {
var d = locals[cdt][cdn];
frappe.call({
method: "erpnext.stock.doctype.item.item.itemwise_uom",
args: {
item:d.item_code
},
callback: function(r) {
const uoms =[];
uoms.pop();
for (var i = 0; i<r.message.length; i++) {
uoms.push(r.message[i].uom);
}
frm.set_query('uom', 'items', function(doc, cdt, cdn) {
return {
filters: [
['name','in', uoms]
]
};
});
}
});
}
});
Then reload and check it.
opened 11:23AM - 15 Aug 23 UTC
closed 04:09PM - 22 Feb 24 UTC
bug
valid
(develop branch)
`set_query` method fails on first row field_on_change event … ...
Just trying detect change on "Spec" column to set query on "Spec Value" ...
Code:
```
//
frappe.ui.form.on("Item Spec",{
item_spec(frm) {
//debugger;
frm.set_query("item_spec_value", "item_specs", function (doc, cdt, cdn) {
let row = locals[cdt][cdn];
return {
filters: {spec: row.item_spec}
}
})
}
})
```
First row

Second row

It's working using `setup `event on parent form instead ... but I raised issue because maybe it's needed in different use cases.
Thank You!
Ryan1
March 20, 2024, 5:58am
3
Thanks for your reply…but the code is not working. @NCP
NCP
March 20, 2024, 6:00am
4
I just shared the code, for example, not tested. and also check the GitHub post. maybe helpful for you.
Ryan1
March 20, 2024, 6:03am
5
ok any other filtering way for child table other then set_query?
Ryan1
April 19, 2024, 1:07pm
7
I have made another solution…made the array global and using cur_frm in get_query to filter the needed uom on item_code change in child table. There’s always a solution (logic) though incompatibility in code. @NCP