How to use value both from master and child table

I have a code here to calculate each item lead time based on the item delivery date and the transaction date. This script I wrote for the child table form in Sales Order Item, and it is not working. how to fetch the transaction date from Sales Order master? I input the result into duration field.

frappe.ui.form.on('Sales Order Item', "refresh", function(frm, cdt, cdn){
    var d = locals[cdt][cdn];   
    frm.set_value("custom_item_lead_time", frappe.datetime.get_day_diff( d.delivery_date , d.transaction_date * 86400));
    refresh_field("custom_item_lead_time");
});

Jevon

Hi @jevht
Please try this code. I hope you will help

frappe.ui.form.on('Sales Order Item', {
	item_code:function(frm,cdt,cdn) {
	    cal_auto(frm,cdt,cdn)
	},
	qty:function(frm,cdt,cdn){
	    cal_auto(frm,cdt,cdn)
	    
	}
});
function cal_auto(frm,cdt,cdn){
    frm.set_value("custom_item_lead_time", frappe.datetime.get_day_diff( d.delivery_date , d.transaction_date * 86400));
}

Thank You!

Hi thankyou for replying,

the script doesn’t work. The lead time is not showing on each item.

Jevon

Hi I found the solution. Here is my script:

frappe.ui.form.on("Sales Order", "delivery_date", function(frm) {
  frm.set_value("custom_lead_time", frappe.datetime.get_diff(frm.doc.delivery_date, frm.doc.transaction_date ) * 86400);
})

then I set the custom filed “custom_lead_time” in Sales Order Doctype as time duration to get the duration formatting.