Using custom script to change the value of a field in child table based on some value.
I tried doing this in a child table script:
frm.set.value(cdt, cdn, 'field', someVariable);
It doesn’t work and returns an error in the console.
But if I use this:
table.field = someVariable;
where table
is the locals[cdt][cdn]
object, it works fine.
I don’t get the difference. Can someone help explain?
peterg
March 13, 2022, 8:33am
#2
If you get an error, it’s always very helpful to post it. Just looking at what you’ve got here, one problem is that the method is actually set_value
, not set.value
.
Generally speaking, using set_value is preferable because it triggers event hooks for the field change. If you just set the locals variable, you won’t.
Got it thanks for the tip. I just made a typo. I meant frm.set_value
. I get an error Uncaught (in promise) frm.set_value
.
frappe.ui.form.on('Sales Invoice Item', {
childTableField:function(frm, cdt, cdn){
let obj = locals[cdt][cdn];
// frm.set_value(cdt, cdn, 'fieldToUpdate', `string value`) // this doesn't work
obj.field= 'string value'; // this works
refresh_field('obj');
}
});
jof2jc
March 13, 2022, 10:18am
#4
Use
frappe.model.set_value(cdt, cdn, ‘fieldToUpdate’, string value
)
Set_value triggers field change event
2 Likes