Update Parent field when Child field is a certain value

Hello all,

Im new to ERPNext and coding, I am trying to achieve a scenario where when in Journal entry, if someone adds a row and the account field in child table is value x for example, the the parent field(user remark) should be set to y value.

Here is the code i tried but is not working properly:

frappe.ui.form.on(‘Journal Entry Account’,‘debit’,function(frm,cdt,cdn){
{
if(frm.doc.account == “Cash-ABC”){
console.log(“test success”);
cur_frm.doc.user_remark = “Test”;
cur_frm.refresh_field(‘user_remark’);
}
else console.log(“fail”);
}
});

frappe.ui.form.on("Journal Entry Account","debit",function(frm,cdt,cdn){
let row=locals[cdt][cdn]
if(row.account == "Cash-ABC"){
    console.log("test success");
    //cur_frm.doc.user_remark = "Test";
    cur_frm.set_value("user_remark","Test");
    // for child table
    // frappe.model.set_value(cdt,cdn,'fieldname','value')
    cur_frm.refresh_field("user_remark");
}
else console.log("fail");

});

1 Like

Thank you!! it worked.

1 Like