Script ChildTable

I do this script for calcute the margin on X doctype

frappe.ui.form.on("Oportunidad","refresh", function(frm)
{
var total = 0
total =  flt(frm.doc.cmensual)/ (1 - flt(frm.doc.margen/100))
frm.doc.pmensual= total;
})

I need to do the same but in Childtable I don’t know do that.


Can you help me ?

Try something like this:

frappe.ui.form.on("Child Table Name","refresh", function(frm, cdt, cdn) {
           // Child table elements
		var child = locals[cdt][cdn]; 

            // Parent elements
		var doc = frm.doc;

            //Your Calculations here

		}
})
2 Likes

Hi, Kanchan

I try to this. But doesn’t work

The ChildTable exist in Doctype “Oportunidades”, the customscript is for this doctype or for de doctype the Childtable?

The script is:

frappe.ui.form.on(“VersionesCRM”,“Refresh”, function(frm, cdt, cdn) {
// Child table elements
var child = locals[cdt][cdn];
var total = 0;

        // Parent elements
	var doc = frm.doc;

        //Your Calculations here

child.pmensual = flt(child.cmensual)/ (1 - flt(child.margen/100));
frappe.model.set_value(cdt,cdn,‘pmensual’, )
cur_frm.refresh();
}
})

But the field on Childtable doesn’t show the calculate. :smile:

any idea? thanks

You can so do this

cur_frm.cscript.fieldname_in_your_childtable = function( doc, cdt, cdn) {
    var d = locals[cdt][cdn];
var some_value = /*YOUR CALCULATION*/ ;
        d.field_to_be_changed = some_value;
        refresh_field("YOUR_CHILD_TABLE_FIELDNAME")
}

Try this in the Opportunidad custom script file

frappe.ui.form.on("VersionesCRM", {
    cmensual: function(frm, cdt, cdn) {
        var d = locals[cdt][cdn];
        frappe.model.set_value(d.doctype, d.name, "pmensual", d.cmensual / (1 - ( d.margen / 100)));
    }
});

frappe.ui.form.on("VersionesCRM", {
    margen: function(frm, cdt, cdn) {
        var d = locals[cdt][cdn];
        frappe.model.set_value(d.doctype, d.name, "pmensual", d.cmensual / (1 - ( d.margen / 100)));
    }
});
2 Likes

Thank You!! @cpurbaugh

I work the script

:slight_smile:

1 Like