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
- 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();
});
}
});