Require Help to identify the row to update the value

Backgroup:

In the attendance docType added two Button Time In Click and Time Out Click

Requirement
On click of Time In Click A row in the Child Table is added “Additinal Attendance”

frappe.ui.form.on(“Attendance”, {
refresh: function(frm){
frm.add_custom_button(“Time In Click”, function() {
frm.set_value(“time_in”, frappe.datetime.now_datetime());
var child = frappe.model.add_child(cur_frm.doc, “Attendance”, “additional_attendance”);
child.checkin = frappe.datetime.now_datetime();
cur_frm.script_manager.trigger(“checkin”, child.doctype, child.name);
cur_frm.refresh_field(“additional_attendance”);
frm.save();
});
}
});

The above code works in terms of inserting time into the Child Table

  1. On click of the Time Out require help in following custom script for pick first the latest row and then insert the time.

frappe.ui.form.on(“Attendance”, {
refresh: function(frm){
frm.add_custom_button(“Time Out Click”, function() {
frm.set_value(“time_out”, frappe.datetime.now_datetime());
frm.doc.docstatus = 1;
frm.save();
});
}
});

created a custom script triggered on Save to create a child document type (table) and transfer value from parent document type.
But getting the error on saving.

frappe.ui.form.on(“Attendance”, “validate”, function(frm) {

                var child = frappe.model.add_child(cur_frm.doc, "Attendance", "additional_attendance");
			    child.checkin = cur_frm.doc.time_in;
			    child.checkout = cur_frm.doc.time_out;
                cur_frm.refresh_field('additional_attendance');

});