Need to copy parent field value in child field after adding row dynamically


I have added child table row dynamically using frappe.model.add_child, after adding if i give for_quantity value in parent table its should get copied to child table.

frappe.ui.form.on(“Job Card”, {
refresh: function(frm,cdt,cdn) {
var row = frappe.model.add_child(cur_frm.doc, “Job Card Time Log”, “time_logs”);
cur_frm.from_time = frappe.datetime.now_datetime();
row.from_time = cur_frm.from_time;
cur_frm.to_time = frappe.datetime.now_datetime();
row.to_time = cur_frm.to_time;
row.completed_qty = cur_frm.doc.completed_qty;
row.completed_qty = cur_frm.for_quantity;
cur_frm.script_manager.trigger(“time_logs”, row.doctype,;

I gave this script its adding row dynamically but when i give for_quantity its not getting copied to child table field completed_qty

Kindly assist ,i have tried many other possible scripts for the same.

Thanks in advance!

Try to use frm.add_child method in the handler for quantity field.

Thanks for the info, it worked by giving below script in parent table,

for_quantity: function(frm) {
$.each(frm.doc.time_logs || , function(i, d) {
if(!d.for_quantity) d.completed_qty = frm.doc.for_quantity;

and below in child table,

frappe.ui.form.on(“Job Card Time Log”,
completed_quantity: function(frm, cdt, cdn) {
if(!frm.doc.for_quantity) {
erpnext.utils.copy_value_in_all_rows(frm.doc, cdt, cdn, “time_logs”, “completed_qty”);

1 Like