PICK_MIX3d
Hello,
I used a custom script and it works perfectly but it does not work when i convert it to a child table for use in another document. Please help as i only need this simple function, can you possibly rewrite for to use in a child table. Fieldname 1 is calc 1 , fieldname 2 is calc 2 and fieldname 3 is calc 3. I created this code for a custom doctype named nestle quarterly. Please help.
cur_frm.cscript.calc1 = function(doc, cdt, cdn) {
if (doc.calc1 && doc.calc2) {
doc.calc3 = doc.calc2/doc.calc1*100;
refresh_field(ācalc3ā);
}
}
cur_frm.cscript.calc2 = cur_frm.cscript.calc1;
Hi,
When converted to a child table you need to āmoveā the custom script to the parent form.
E.g.: letās say you have this DocType named A (and is of stand-alone type). Obviously you create a custom script for DocType A. If you edit the A DocType and make it a child table of DocType B, then, you need to change the DocType field in the Custom Script form for the script you created from A to B.
I found this myself. Maybe thereās a better way but I donāt know it.
Apart from the changes provided by @sorin.negulescu, you need to change the code little bit.
If all the fields are in child doctype, then your code will look like this:
cur_frm.cscript.calc1 = function(doc, cdt, cdn) {
var d = locals[cdt][cdn];
if (d.calc1 && d.calc2) {
d.calc3 = d.calc2/d.calc1*100;
refresh_field('calc3');
}
}
cur_frm.cscript.calc2 = cur_frm.cscript.calc1;
2 Likes