I have created my three variables, aaa, bbb, & ccc in my sales order header and placed this script on the sales document but nothing is happening. I have refreshed my cache. Can anyone advise on what I’m missing?
function on_change_aaa_bbb(doc, cdt, cdn){
if (doc.aaa && doc.bbb){
doc.ccc = doc.aaa*doc.bbb;
cur_frm.refresh()
}
}
I have placed this simple logic where you indicated to place logic:
function on_change_aaa_bbb(doc, cdt, cdn){
if (doc.aaa && doc.bbb){
doc.ccc = doc.aaa*doc.bbb;
cur_frm.refresh()
The messages come up when I input values in fields aaa and bbb.
How come the computation does not automatically occur in field ccc?
@saurabh6790 : Thank you, I’ve tried the below and still no joy, Can you point out what I’ve missed? Thanks in advance:
frappe.ui.form.on(“Quotation”, “bbb”, function(frm) {
msgprint(frm.doc.bbb);
});
frappe.ui.form.on(“Quotation”, “aaa”, function(frm) {
msgprint(frm.doc.aaa);
});
frappe.ui.form.on(“Quotation”, “ccc”, function(frm) {
var qty = doc.aaa*doc.bbb;
cur_frm.set_value("doc.ccc", qty);
msgprint(frm.doc.ccc);
-Thanks for bearing with me and assisting me as well. It’s gentleman like yourself and @kolate_sambhaji that make the ERPNext journey enjoyable
@kolate_sambhaji - I’ve been testing it and I see the value ccc is only updated when value bbb changes . When value aaa changes, the calculation remember only the original value entered and doesn’t work with the new value that’s been input.
For example bbb starts as 10 ,and aaa as 5, ccc is calculated as 50, if I then change aaa to 10, the value in ccc remains as 50, However if I change bbb to 20, then ccc shows 100 even though aaa has been chnaged to 10 and the output in ccc should be now 200 .
in above example, sales order is doctype on which you have written custom script
ccc,aaa,bbb fieldname, if value of field ccc changes then your script run
you can also write event_name instead of fieldname,
Event name can be validate, refresh, onload
If you write validate, then script will run before save
frappe.ui.form.on(“Sales Order”, “validate”, function(frm) {