Edit after save

Can I change value of read only field after saving it?

If I click on punch out button after saving it, current out time is not being updated…

Have you coded that button yourself ? Does it save the attendance or no ? Save after changing and it should be okay

Hii @root13F,
Yes Punch in and Punch out button are custom. When I click on punch in button it updates In time field and then I save attendance . Now I want to click on punch out , so it will update out time(current time) and then submit it.

yes you can

How??

You can make changes to the form customize

@Saditi,

i think you can use

frm.save()

followed by

frm.save(“Submit”)

please refer to the updated/new documentation that is available at: Form Scripts

Can you please explain?

Thanks for your help,
But I am still not able to modify time when I click on Punch out button, after saving.

why is that? can you share more details on what is the exact problem/error that you are facing?

can you also share your custom script here?

cur_frm.add_fetch(‘employee’, ‘company’, ‘company’);
cur_frm.add_fetch(‘employee’, ‘employee_name’, ‘employee_name’);

cur_frm.cscript.onload = function(doc, cdt, cdn) {
if(doc.__islocal) cur_frm.set_value(“attendance_date”, frappe.datetime.get_today());
}

cur_frm.cscript.punch = function(doc, cdt, cdn) {
if(doc.__islocal) cur_frm.set_value(“in_time”, frappe.datetime.now_datetime());
}

cur_frm.cscript.punch_out = function(doc, cdt, cdn) {
if(doc.__islocal) cur_frm.set_value(“out_time”, frappe.datetime.now_datetime());

	var start = cur_frm.doc.out_time;
    var end = cur_frm.doc.in_time;
	var hour=0;
	var minute=0;
	var second=0;

	var splitStart= start.split(':');
	var splitEnd= end.split(':');
	hour = parseInt(splitStart[0])-parseInt(splitEnd[0]);
	minute = parseInt(splitStart[1])-parseInt(splitEnd[1]);
	hour = hour + minute/60;
	minute = minute%60;
	cur_frm.set_value("total_time",hour+minute);

}

cur_frm.fields_dict.employee.get_query = function(doc,cdt,cdn) {
return{
query: “erpnext.controllers.queries.employee_query”
}
}

This is my js file.
→ I click on “punch in” button it loads “in time”(current time)
→ Then “save” attendance.
→ Now attendance is saved as draft.
→ I want to click on “punch out”, so it will load current time(of system) in “out time” field and calculate difference between both time fields.
→ Later clicking on “submit” button will store attendance permanently.

Hope you will now get my problem…
Looking forward for your reply.

@Saditi

If document once’s saved then __islocal will be undefined.

In place of __islocal you can use __unsaved on punch_out button.

I hope this solve your problem.

Thanks @ROHAN_JAIN1 ,
Still not able to update “out time” field with current time.

cur_frm.cscript.punch_out=function(){
	if(cur_frm.doc.__islocal === undefined) {
		cur_frm.set_value("time_out",frappe.datetime.now_datetime())
	}
}

cur_frm.cscript.punch_in=function(){
	if(cur_frm.doc.__islocal) {
		cur_frm.set_value("time_out",frappe.datetime.now_datetime())
	}
}

Try above Script, I have made some conditional changes @Saditi

1 Like

Thanks a lot @ROHAN_JAIN1, It worked…

1 Like