Ninja
September 19, 2016, 7:45am
1
Hi All ,
I have a custom script to calculate the total in the child and set it on parent doc , but it is not working , please help
frappe.ui.form.on("Cutting Issue", "qtyno", function(frm, cdt, cdn) {
// code for calculate total and set on parent field.
total_qty = 0;
$.each(frm.doc.cutting_iss || [], function(i, d) {
total_qty += flt(d.qtyno);
});
frm.set_value("total", total_qty);
});
Thanks
@Ninja ,
Is there any errors, if yes can you share the console logs ?
1 Like
Ninja
September 19, 2016, 7:49am
3
Hi @makarand_b ,Thanks for reply . I checked in the console , no errors . What should I do ?
Thanks
In that case please check if all the field names like cutting_iss
, qtyno
, total
are correct or not.
1 Like
Ninja
September 19, 2016, 7:56am
5
Thanks for reply @makarand_b . Yes I checked many times , For clarification
qtyno
field in the child table
total
field in the parent doc
child table name cutting_iss
child table field name ci
Both the child and parent are in the same doc cutting issue
Please help
Thanks
@Ninja
Try running this script on [quote=“Ninja, post:1, topic:16099”]
total_qty = 0;
$.each(frm.doc.cutting_iss || [], function(i, d) {
total_qty += flt(d.qtyno);
[/quote]
chrome developer console, adding console.log()
so that you are sure that you get some output from this piece of code.
what is the Child table Doctype name ?
Cutting Issue
or cutting_iss
1 Like
Ninja
September 19, 2016, 8:02am
8
Hi @makarand_b . Thanks for reply . Child table doctype name is cutting_iss
Please help
Ninja
September 19, 2016, 8:03am
9
Hi @shreyasp Thanks for reply , that code just bricks the system .
Please help
Ninja:
frappe.ui.form.on(“Cutting Issue”, “qtyno”, function(frm, cdt, cdn) {
should be frappe.ui.form.on("Child Table DocType", "qtyno", function(frm, cdt, cdn) {
replace cuttong_iss
by child table field name ci
1 Like
Bricks Could you explain ?
Ninja
September 19, 2016, 8:07am
12
Yes many thanks @makarand_b . It is working with the below code . you found the error sir .
frappe.ui.form.on("Cutting Iss", "qtyno", function(frm, cdt, cdn) {
// code for calculate total and set on parent field.
total_qty = 0;
$.each(frm.doc.ci || [], function(i, d) {
total_qty += flt(d.qtyno);
});
frm.set_value("total", total_qty);
refresh_field("total");
});
Many thanks
1 Like
Ninja
September 19, 2016, 8:07am
13
Hi , @shreyasp , The above code solved my issue . Thanks a lot for helping me .