Custom script help - delivery note

I need to fetch the expiry date from the “Batch” doctype to the delivery note item. When the batch is selected the expiry date should automatically be fetched upon saving the document. I tried below but it does not work!

frappe.ui.form.on("Delivery Note Item", {
     before_save(frm) {
		 for(var i=0; i<frm.doc.items.length; i++){
			cur_frm.add_fetch("batch_no","expiry_date","expiry_date"); 
				 
			 }
		 }
    }
});

Hi @thelahera,

In child-level script does not work for before_save.

When you select batch no then will automatically fetch the value from Batch.
So you can apply it.

frappe.ui.form.on("Delivery Note Item", "batch_no", function(frm, cdt, cdn) {
    var d = locals[cdt][cdn];
        frappe.db.get_value("Batch", {"name": d.batch_no}, "expiry_date", function(value) {
            d.expiry_date = value.expiry_date;
        });
});

Thank You!

1 Like

Unfortunately, this does not work. I tried many times to correct it without bothering you but it did not work. Thank you so much for your effort.

Hi @thelahera,

Please check it:
https://docs.erpnext.com/docs/v12/user/manual/en/customize-erpnext/custom-scripts/fetch%20value%20in%20child%20table%20field

Thank You!