Row is getting added twice on child table

Hi,

I want to add a row dynamically to Job card child table time logs. I have given below script,

frappe.ui.form.on(“Job Card”, {
refresh: function(frm,doc,cdt,cdn) {
var fromtime = frappe.datetime.now_datetime();
var totime = frappe.datetime.now_datetime();
var child = frm.add_child(“time_logs”);
frappe.model.set_value(child.doctype, child.name, “completed_qty”, doc.for_quantity);
frappe.model.set_value(child.doctype, child.name, “from_time”, fromtime);
frappe.model.set_value(child.doctype, child.name, “to_time”, totime);
frm.refresh_field(“time_logs”);
}
});

Its getting added when i click on new job card, but when i click on save, the rows are getting added twice,


Not sure where its wrong, kindly help, i also need to copy for quantity field from parent to child table field completed qty.

Thanks in advance!

Hi,
You dont need to set value, you can use your child object.
for e.g.
child.from_time = fromtime
child.to_time = totime
and then
frm.refresh_fields('time_logs')

Hi,
Ok i gave like this child.from_time = fromtime , the problem is when i save two rows are getting added.

On what event you have written this code, may be it is getting called multiple times. Please debug it, print something there and run it you will get to know whether it is getting called multiple times.