Hi Team ,
I want to save a child table perticler filed in database . field type is data.
without saving a all form simple save a perticler field database.
can you help me .
Hi Team ,
I want to save a child table perticler filed in database . field type is data.
without saving a all form simple save a perticler field database.
can you help me .
try frappe.db.set_value("Doctype", "doc_name", "field_name", "value")
@Saranesh_A my value is dyanamically change . like i want to set live timer . in db
my parent doctype is Timesheet and child doctype is Timesheet Detail my field name is custom_live_timer . type is Data.
@Saranesh_A my usecase is so user start a timer then manger does not have a know . how much time it user take so for that we have to build a concept live timer .
means inted of save overall form save only one field in database.
Have you tried with start timer custom button in timesheet
once it is started, u can click on resume timer to see the live timer
yes it see on live timer i want to save live timer filed in DB at every 10 sec .
that i want to do
and the value inside the live timer field is change at every sec. this value is set from the dialog box at every 10 sec .
please help i am near about an solution .
@Saranesh_A please help me For Database value ste i have used below script
let timers = {};
let saveIntervals = {}; // Properly initialize saveIntervals
frappe.ui.form.on('Timesheet Detail', {
custom_timer_status: function (frm, cdt, cdn) {
let row = frappe.get_doc(cdt, cdn);
if (row.custom_timer_status === "Active") {
// Reset the timer display
row.live_timer = "00:00:00";
frm.refresh_field("time_logs");
let startTime = new Date();
// Start the live timer
timers[row.name] = setInterval(() => {
let elapsed = new Date(new Date() - startTime);
let hours = String(elapsed.getUTCHours()).padStart(2, '0');
let minutes = String(elapsed.getUTCMinutes()).padStart(2, '0');
let seconds = String(elapsed.getUTCSeconds()).padStart(2, '0');
// Update the live timer field
row.live_timer = `${hours}:${minutes}:${seconds}`;
frm.refresh_field("time_logs");
}, 1000);
saveIntervals[row.name] = setInterval(() => {
frappe.db.set_value('Timesheet Detail', row.name, 'live_timer', row.live_timer);
}, 10000);
frappe.msgprint(`Timer started for row: ${row.idx}`);
} else {
clearInterval(timers[row.name]);
delete timers[row.name];
clearInterval(saveIntervals[row.name]);
delete saveIntervals[row.name];
frappe.msgprint(`Timer stopped for row: ${row.idx}`);
frm.refresh_field("time_logs");
location.reload();
}
}
});
Before puting saveInterval[row.name] it working fine but after that it need to we need to complete timesheet twoice . ?