Calculation in Child Table

I am trying to do a calculation in the child table to calculate commission due everytime the commission tier field is changed. I’ve put the custom script under “Sales Order” and created this custom script. However, I cannot get the fields to update with the correct values.

frappe.ui.form.on("Sales Team", "comms_tier", function(frm) { total_comms_due = comms_tier * allocated amount; });

1 Like

Hi @Justin_Lu,

check below code
frappe.ui.form.on("Sales Team", "comms_tier", function(frm, cdt, cdn) { var child = locals[cdt][cdn]; total_comms_due = child.comms_tier * child.allocated amount; frappe.model.set_value(cdt, cdn, 'total_comms_due', ) });

Thanks, Rohit
`

2 Likes

Thanks for the help!! Did some changes to the code and it worked!

frappe.ui.form.on("Sales Team", "comms_tier", function(frm, cdt, cdn) { var child = locals[cdt][cdn]; child.total_comms_due = (child.comms_tier * child.allocated_amount / 100) + child.incentives; cur_frm.refresh(); });

3 Likes

Hi @rohit_w
I tried the same way but it is not working for me.
May you please check what is the issue in this?

frappe.ui.form.on("Sales Order", "fill_items", function(frm, cdt, cdn){
msgprint("Test");
var d =locals[cdt][cdn];

 for (var i in frm.doc.items)
    {     
	
	 var d1 =  { "item_code":  frm.doc.items[i].item_code
                   };      
frappe.call({
                method: "library_management.item_script.generate_custom_codes",
                args: d1,
                callback: function(r) { 
                frappe.model.set_value(cdt, cdn, 'custom_code_ref',r.message);
               }
           
            });
   }
});

Regards
Ruchin Sharma

Hi @ruchin78

can you explain it?

Add code console.log(r.message) and share the output

Thanks

Hi @rohit_w
I am able to do it with this.

https://discuss.frappe.io/t/not-able-to-update-value-in-child-table-solved/16590/9

Regards
Ruchin Sharma

Thanks for the tips, i did the changes and now its working…GREAT