Need help with this script

Hi All,

I am trying to filter the item_code in the production order based on the selected sales order with the below script , but with no success , please help me to debug this code.

frappe.ui.form.on("Production Order", {
item: function(frm) {
frappe.call({
"method": "frappe.client.get_value",
"args": {
"doctype": "Sales Order",
"filters": {"item_code": cur_frm.doc.item},
"fieldname": ["sales_order"]
}, 
callback: function(r) { 
cur_frm.set_query("item_code", "items", function(doc, cdt, cdn){
return {
"filters": {
"sales_order": ["=",r.message.sales_order],
}
}
});
}
});
}
});

Thanks in advance

Even tried the below script , getting error in the console : Uncaught TypeError: Cannot read property ā€˜get_fieldā€™ of undefined

frappe.ui.form.on("Production Order", "refresh", function (frm, cdt, cdn) {
    frm.set_query("production_item", "item", function () {
         return{
		filters: {
			"sales_order": frm.doc.sales_order
		}
         }
    });
});

Please help

Thanks in advance

Hi @srinivasragav,

You need to write get_query for item_code with sql query, for example see below code

Thanks, Rohit

2 Likes

Try to set set_query inside ā€œonloadā€ function.

1 Like

Hi @rohit_w ,

Many thanks for responding , I tried your suggestion but I am getting this error , when I click on the sales order field , AttributeError: ā€˜moduleā€™ object has no attribute ā€˜get_sales_orderā€™

frappe.ui.form.on("Production Order", "refresh", function (frm, cdt, cdn) {
    cur_frm.fields_dict['sales_order'].get_query = function(doc, cdt, cdn) {
	return{
		query: "erpnext.controllers.queries.get_sales_order",
		filters: {'production_item': doc.item}
	}
    }
});

Please help

Hi @nabinhait . Sir I am novice could you please explain me how to do that ?

Thanks

If the refresh function in the above code is removed it does not show any error , but still the list is not getting filtered. Please help