Need help with child table calculation

Hi All ,

I am trying to do a calculation in a child table with the below scripts , neither of the below script works , please help

frappe.ui.form.on("Cutting Iss", "qtykg", function(frm, cdt, cdn) {
var child = locals[cdt][cdn];
qtykg = child.qtyno * child.wtpc;
frappe.model.set_value(cdt, cdn, 'qtykg')
refresh_field("ci");
});



frappe.ui.form.on("Cutting Iss", "qtykg", function(frm, doctype, name) {
  var row = locals[doctype][name];
  row.qtykg = row.qtyno * row.wtpc;
  refresh_field("ci");
});

I am not getting any error in the console but it is not working

Parent docname Cutting Issue
Child table name Cutting Iss
Child table field name ci
fields in the child table qtyno qtykg wtpc

Please help

Thanks

Even tried this , but no luck , could anyone help me please , thanks

frappe.ui.form.on("Cutting Iss", "qtykg", function(frm, cdt, cdn) {
       var d = locals[cdt][cdn];
       frappe.model.set_value(cdt, cdn, "qtykg", d.wtpc * d.qtyno);
refresh_field("ci");
});

Assuming you want to set value to ci

frappe.ui.form.on("Cutting Iss", "qtykg", function(frm, cdt, cdn) {
       var d = locals[cdt][cdn];
       frm.set_value("ci", flt(d.wtpc * d.qtyno))
       refresh_field("ci");
});
1 Like

Thanks for the reply @saurabh6790 , it did not work ,

I want to set the value for qtykg field which is in a table cutting iss , the field name for the child table is ci .

Please help

can you share the use case ?

1 Like

Yeah sure @makarand_b Thanks for the reply ,

I do have two fields inside a child table cutting iss which is in a parent cutting issue , I want to multiply qtyno and wtpc fields and put that value in qtykg field , all these fields are in the same child table cutting iss , the child table field name is ci .

Could you please help me

Thanks

then write a trigger on qtyno or wtpc instead on qtykg.[quote=“Ninja, post:2, topic:16102”]
frappe.ui.form.on(“Cutting Iss”, “qtykg”, function(frm, cdt, cdn)
[/quote]

try

frappe.ui.form.on("Cutting Iss", "qtyno or wtpc", function(frm, cdt, cdn)

1 Like

Thanks for the reply @makarand_b , Yes I did but no luck ,

 frappe.ui.form.on("Cutting Iss", "qtyno", function(frm, cdt, cdn) {
       var d = locals[cdt][cdn];
       frm.set_value("qtykg", flt(d.wtpc * d.qtyno))
       refresh_field("ci");
});

Please help

Thanks

Hi @Ninja,

Try below code

 frappe.ui.form.on("Cutting Iss", {
	qtyno: function(frm, cdt, cdn){
		frm.trigger("calculate_qtykg")
	},
	
	wtpc: function(frm, cdt, cdn){
		frm.trigger("calculate_qtykg")
	},
	
	calculate_qtykg: function(frm, cdt, cdn){
        	var d = locals[cdt][cdn];
        	frappe.model.set_value(cdt, cdn "qtykg", flt(d.wtpc * d.qtyno))
	}
})
1 Like

Hi @rohit_w

Thanks for the reply , the above code bricks the system , tried debugging in console but it bricks .

Please help

Hi @Ninja,

Check any error on browser’s console log

1 Like

Thanks for the reply @rohit_w . I am getting this error in the console , tried debugging the code to my best possible extent but still unable to debug ,

Uncaught SyntaxError: missing ) after argument list

Please help

Thanks

Hi @rohit_w .

The below script works only if I multiply a field with a number ,

frappe.ui.form.on("Forgin Iss", "issqty1", function(frm, cdt, cdn) {
       var d = locals[cdt][cdn];
       frappe.model.set_value(cdt, cdn, "tot", d.issqty1 * 6);
});

but if I replace the numerical value with a field , it is not working 

frappe.ui.form.on("Forgin Iss", "issqty1", function(frm, cdt, cdn) {
       var d = locals[cdt][cdn];
       frappe.model.set_value(cdt, cdn, "tot", d.issqty1 * d.wtkg);
});

both issqty1 and wtkg fields are float fields, 

Please help

Thanks

1 Like

I got it working with few modifications to the above code . Thanks @rohit_w @makarand_b @saurabh6790