What is the difference between frm.set.value and a simple `=` operator?

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?

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.

image

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');
  }
});

Use
frappe.model.set_value(cdt, cdn, ‘fieldToUpdate’, string value)

Set_value triggers field change event

3 Likes

Thx, I was looking for a way to change field-values without triggering events. This did the trick:
frm.doc.my_fieldname = 0;
refresh_field(“my_fieldname”);

1 Like

thank you this way make my code work like charm