I’m trying to set a field’s value using the custom script below:
frappe.ui.form.on("Sales Invoice", "outstanding_amount", function(frm, dt, dn) {
var d = locals[dt][dn];
frappe.model.set_value(dt, dn, "outstanding_tranches", (d.outstanding_amount / d.tranch_amount));
});
The problem is:
The script doesn’t work unless I use the “refresh” trigger but I want it to run whenever the value in the ‘outstanding_amount’ field changes
When I use the “refresh” trigger, the field get’s updated on Saving BUT the status of the Sales Invoice form remains as ‘Not Saved’. I need to click ‘Save’ a second time before the status is properly updated and the Submit button appears
The fields aren’t in a child table right? If that’s so, you might want to change the frappe.ui.form on to pass just frm (no need for dt, dn since those are for child tables), and using frm.doc.outstanding_amount, frm.doc.outstanding_tranches to access the values.
Refresh is still the only trigger that works and it doesn’t update the status field. I have to still manually click on Save (if the doc is in Draft) or Update (if the doc is Submitted) before the status of the doc gets updated accordingly
It’s as though the set_value method requires a manual trigger or something…
It seems that the field trigger doesn’t work unless the field is manually updated. Not sure if there’s a reason for that
I don’t mind using the “refresh” trigger but I need to get around the ‘Not Saved’ issue which always requires the user to manually click on the Save button a second time (or Update button if the document is in a Submitted state)
Hi,facing the same issue i am trying to set value in js after document submitted value is also set but problem is i have to click on the update button…i need to update this via code is it possible? any idea