Filter on child table based on the value of another table's field

I have a requirement where I want to restrict the user based on workflow_state of item.
If the item is approved then only it should be shown in the item help.

Below is my code which is working for stock entry but the same code is not working for purchase order.

Stock Entry (Working):

frappe.ui.form.on("Stock Entry", "onload", function(frm){

cur_frm.set_query("item_code", "items",  function (doc, cdt, cdn) {
return { 
"filters": [
["Item","workflow_state", "=", "Approved"]
] 
}
});
});
Purchase Order (Not Working):

frappe.ui.form.on("Purchase Order", "onload", function(frm){

cur_frm.set_query("item_code", "items",  function (doc, cdt, cdn) {
return { 
"filters": [
["Item","workflow_state", "=", "Approved"]
] 
}
});
});

I appreciate if someone can help me in this regard.

Regards
Ruchin Sharma

@ruchin78 ever get this working?

@cpurbaugh
Here is the working code:

frappe.ui.form.on("Purchase Order", "refresh", function(frm) {
cur_frm.fields_dict['items'].grid.get_field('item_code').get_query = function(doc, cdt, cdn) {
	return {
		filters:[
			['Item', 'workflow_state', '=', 'Approved']
		]
	}
}
});

Regards
Ruchin Sharma

2 Likes