Client script for child table

Hello,
Can someone please help me in basic query, as I am new in this.

I want to add client script for simple table below.

I want to show sum of column “Amount” from all rows in filed “Total Fee Paid” on Refresh/Save event.

how to do that?

ERPNext: v14.x.x-develop () (develop)
Frappe Framework: v15.x.x-develop () (develop)

Hi @umarless,

Please check the syntax.

DocType → Parent DocType
your_child_table_fieldname → Set your child table field name
d.amount → Set your amount field name which is in the child table
total_paid_amount → Set your parent total field name.

frappe.ui.form.on('DocType',  {
    validate: function(frm) {
        var total_paid_amt = 0;
        $.each(frm.doc.your_child_table_fieldname,  function(i,  d) {
            amt += flt(d.amount);
        });
        frm.set_value("total_paid_amount", amt);
    } 
});

Please set the doctype, child table field name, and other field names accordingly.

Reference:

I hope this helps.
Thank You!

1 Like

Hello,

I tried above script, please check the screenshots.

but sum of total amount not updating.

DocType → Tasmeem Projects
your_child_table_fieldname → design_fee_table (Child Table Name: “Design Fee Table” )
d.amount → d.design_amount
total_paid_amount → total_design_fee_paid

Please highlight if any mistake found, thanks in advance.

Hi @umarless,

Please apply it.

frappe.ui.form.on('Tasmeen Projects',  {
    validate: function(frm) {
        var tdfp = 0;
        $.each(frm.doc.design_fee_table,  function(i,  d) {
            tdfp += flt(d.design_amount);
        });
        frm.set_value("total_design_fee_paid", tdfp);
    } 
});

Then reload and check it.
On save time total will calculate.

Thank You!

2 Likes

Thanks for replying Nihantra,

Just tried the above script, but its not working.

There is no error, but sum is not getting calculated in that field “Total Fee Paid”.

Please check the field name, doctype, and table field name.

Because we applied script on lots of servers. and it is workable.
Please again check it.

Thank You!

1 Like

Hi @umarless,

Please check it.

Parent DocType:

Child Table DocType:

Client Script:

Code:

frappe.ui.form.on('Test DocType',  {
    validate: function(frm) {
        var ttl = 0;
        $.each(frm.doc.test_child_table,  function(i,  d) {
            d.amount = d.qty * d.rate;
            ttl += flt(d.amount);
        });
        frm.set_value("total", ttl);
    } 
});

Output:

I hope this helps.
Thank You!

1 Like