Row is getting added twice on child table


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,, “completed_qty”, doc.for_quantity);
frappe.model.set_value(child.doctype,, “from_time”, fromtime);
frappe.model.set_value(child.doctype,, “to_time”, totime);

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!

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

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.