Please HELP! ---(Calculate percentage in child table based on a grand total located in the Doctype)

I have a child table (CONTEOS) with two columns: “n_granos” and “porcentaje” in a Doctype call “Mieles Pampero”. In the Doctype I have a field call “entomofilos”. I have done the script for “total” that sum “n_granos”. I want to calculate the “porcentaje” / percentage in each row like: n_granos/total. I have done the srcipt below but it does not work, becuase it does not refresh the number each row I include.

. Can somebody help me? Thanks!!

frappe.ui.form.on(“CONTEOS”, { n_granos:function(frm, cdt, cdn){ var child = locals[cdt][cdn]; if(d.tipo_de_polinizacion == “Entomofilia” ){frappe.model.set_value(cdt,cdn ,“porcentaje”, child.n_granos / cur_frm.doc.entomofilos * 100);}}});