Help in Custom Script for Sales Invoice

Please let me know the problem in my code for Custom script for sales invoice.

frappe.ui.form.on(“Sales Invoice Item”, “batch_no”, function(frm, cdt, cdn){
var flag = {{frappe.db.get_value(“Item”,item_code, “has_batch_no")}};
if(flag)
{
if(frm.doc.selling_price_list == “Nett Rate Standard Selling”)
{
cur_frm.add_fetch(“batch_no”, “nett_rate” , “rate”);
}
if(frm.doc.selling_price_list == “Trade Rate Selling”)
{
cur_frm.add_fetch(“batch_no”, “trade_rate” , “rate”);
}
}
});

I am getting a blank form when running this code.
Thanks

You will need to add the callback function to frappe.db.get_value in Custom Script. Then, In your callback method you can add your code.

e.g.

frappe.ui.form.on("Sales Invoice Item", "batch_no", function(frm, cdt, cdn){
	frappe.db.get_value("Item",item_code, “has_batch_no", function(r){
		if(r.“has_batch_no){
			// your code
		}
		else {
			// something else
		}
	});
});

Thanks, Makarand

1 Like

Tried this but I am still getting a blank form.

Something is not right with frappe.db.get_value . I am not able to figure out.