I have a “reg_inc” doctype.
it has a field “table” - a child doctype called “test_child_table”.
there are three fields in the table “first_data”, “sec_data” and “trhe_data”.
I’m trying to write a custom script to calculate the value of “sec_data”.
The script works, but not as expected.
When the first time click on “save”, the calculation of “sec_data” is not performed.
If, after saving, “first_data” is changed again, then the script is executed.
What could be the problem?
frappe.ui.form.on (‘reg_inc’, {
refresh (frm) {
frappe.ui.form.on (“test_child_table”, “first_data”, function (frm, cdt, cdn) {
var d = locals [cdt] [cdn];
d.sec_data = d.trhe_data * d.first_data;
})
}
})
thanks for the answer.
But your code works the same way as mine.
The first time nothing happens. Calculation takes place preservation and then, after repeated
changing values (same as in my code).
But for experiment I changed the line
var result = d.trhe_data * d.first_data;
per line
var result = 3 * d.first_data;
and the calculation takes place immediately.
I guess that the initial error is due to the fact that at first the trhe_data field is not filled, and therefore the calculation does not occur.
And after saving it already has a value.
How can I solve this problem?