Child table value from Parent form

How can I fetch a field from parent form to a field in child table form?
eg:- I have a custom field Cost Center (cost_center) in Sales Invoice form.
how do I copy the value from this field to Cost Center in all items (child table)?

frappe.ui.form.on("Sales Invoice Item", {
cost_center: function(frm, cdt, cdn) {
	var row = frappe.get_doc(cdt, cdn);
	if(doc.cost_center) {
		row.cost_center = doc.cost_center;
		refresh_field("cost_center", cdn, "items");
	} else {
		this.frm.script_manager.copy_from_first_row("items", row, ["cost_center"]);

This one worked :slight_smile:


There is a small issue ,
when I select item in item table the cost center in item table is changed to Main
any idea why such behavior

@kolate_sambhaji please help

frappe.ui.form.on(“Sales Invoice”,“refresh”, function(){
for (var i =0; i < cur_frm.doc.items.length; i++){
cur_frm.doc.items[i].cost_center = cur_frm.doc.cost_center

this works