Firing a event/function when changing any field value in doc

Hi, I am stuck in a case, where every field is linked to other field, so changing one field value will impact other. so i would to write a script to fire a event when any field value is changed.

Try writing that script on event on_update

@root13F on_update event is not triggering.

In mycase I need to fire event when any field value is changed without save/updating the doc.

Bump.

Create a custom script with following code:

frappe.ui.form.on ('[your doctype here]', 'setup', function(frm){
    for (const fieldname of frm.meta.fields.map(x => x.fieldname)) {
        frappe.ui.form.on(frm.doctype, fieldname, function() {
          // your code here
        });
    }
});
1 Like

@snv Thanks for the response. It really work. For docType having countless docFields it may get problematic while troubleshooting.

I have come up with a modified solution that will save resource as well:

var fieldsArray = ["field1","field2","fieldx"];
frappe.ui.form.on('Job Order', 'setup', function(frm, cdt, cdn){
	for (const fieldname of frm.meta.fields.map(x => x.fieldname)) {
		if(fieldsArray.indexOf(fieldname) != -1){
            // your code here
        }
    }
}
1 Like