Fetch Value Into Child Table Not Working

I created custom link field: sales_person on Sales Invoice. On Sales Invoice Item, I created custom field: comm_rate. The same comm_rate is on Sales Person doctype.

I want to fetch comm_rate form sales person master when adding sales invoice item and calculate commission per item.

I use this custom script but doesn’t work…

frappe.ui.form.on("Sales Invoice Item", "imei_serial_no", function(frm, cdt, cdn) {
	var d = locals[cdt][cdn];

                cur_frm.add_fetch(doc.sales_person, 'comm_rate', 'comm_rate');

Source link-field is sales_person under Sales Invoice parent. Tried this as well but didn’t work cur_frm.add_fetch('sales_person', 'comm_rate', 'comm_rate');

Many examples I see is working for parent table…Tried many combinations but still stuck. Appreciate anybody who can help what’s wrong here?


Add fetch has to be set on onload

You might want to add another handler on “sales_person” to update the commission onchange or just write a server side method via hook so that it can update on save.

Working using below code:

                         method: "frappe.client.get_value", 
                         args: { 
                                doctype: "Sales Person",
			        fieldname: "comm_rate",
			        filters: { name: frm.doc.sales_person},
                         callback: function(r) {
                                 if (r.message){
                                          frappe.model.set_value(cdt, cdn, "comm_rate", r.message.comm_rate);
                                 else {
                                          frappe.model.set_value(cdt, cdn, "comm_rate", 10.0);