Copy parent field data to child table

Hiiii,
Please I need help to copy parent field data to child table… I tried the following script but not works
Parent Doctype is BPE
Field in Parent Doctype is name_22
Child table filed in Parent Doctype is table_2
Field in child table is name_11
Note: Parent and child table is customized not standard Doctypes

frappe.ui.form.on(“BPE”,“refresh”, function(){
for (var i =0; i < cur_frm.doc.table_2.length; i++){
cur_frm.doc.table_2[i]. name_11 = cur_frm.doc.name_22
}
cur_frm.refresh_field(‘table_2’)
});

@Aniket_Shinde1 @bibinqcs @mainul please advise if possible

Thanks in advance

Hi @dufani1,

try something like this:

frappe.ui.form.on("BPE", {
  refresh: function(frm) {
      var last_id = frm.doc.table_2.length - 1;
      frappe.model.set_value(frm.doc.table_2[last_id].doctype, frm.doc.table_2[last_id].name, "name_11", frm.doc.name_22);
  }
});  

Hope this helps.

5 Likes

@lasalesi thanks works but I have to press save twice

Hi @dufani1,

you are welcome :wink:

Saving twice: that might be related to the trigger. You can also use a different trigger than refresh, maybe the change of the name_22 or something like this. Refer to Developer Cheatsheet · frappe/frappe Wiki · GitHub for details on the triggers…

1 Like