Hello Frappe community,
I’m facing an issue in ERPNext version 15 within the Journal Entry form, specifically in the child table accounts (Journal Entry Account).
Problem:
When I add a new row to the accounts table and fill in the party-related fields (party_type, party), the next new row automatically inherits the previous row’s party_type and party values without me selecting them again. This causes repeated data entries and can lead to errors or confusion.
I want to prevent this auto-fill behavior so that each new row starts with empty or default values for party fields, and only the fields I explicitly set should be filled.
I tried to write a client-side script to clear the party fields when a new row is added, but the event to detect new row addition (accounts_add) does not seem to fire reliably in ERPNext v15. Other workarounds also failed.
Thanks.
The problem saved by client script
This code for anyone who need.
frappe.ui.form.on('Journal Entry', {
onload(frm) {
let previous_row_count = frm.doc.accounts ? frm.doc.accounts.length : 0;
frm.accounts_interval = setInterval(() => {
let rows = frm.doc.accounts || [];
if (rows.length > previous_row_count) {
let new_row = rows[rows.length - 1];
frappe.model.set_value(new_row.doctype, new_row.name, 'account', '');
frappe.model.set_value(new_row.doctype, new_row.name, 'debit', 0);
frappe.model.set_value(new_row.doctype, new_row.name, 'credit', 0);
frappe.model.set_value(new_row.doctype, new_row.name, 'party_type', '');
frappe.model.set_value(new_row.doctype, new_row.name, 'party', '');
// frappe.model.set_value(new_row.doctype, new_row.name, 'cost_center', '');
//frappe.model.set_value(new_row.doctype, new_row.name, 'project', '');
// frappe.model.set_value(new_row.doctype, new_row.name, 'reference_type', '');
// frappe.model.set_value(new_row.doctype, new_row.name, 'reference_name', '');
// frappe.model.set_value(new_row.doctype, new_row.name, 'user_remark', '');
previous_row_count = rows.length;
frm.refresh_field('accounts');
}
}, 300);
},
onUnload: function(frm) {
if (frm.accounts_interval) clearInterval(frm.accounts_interval);
}
});