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)
NCP
May 29, 2023, 9:05am
2
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:
Hey @GhadaEbrahim ,
I think, you not proper understand.
Plesae match with field and doctype.
Supplier → Parent DocType
frm.doc.payment_details → Child Table field name in Parent DocType
d.collected_amount → Child table field name which you want to calculate in parent field.
debt_collected_amount → Parent Doctype field name.
frappe.ui.form.on('Supplier', {
validate: function(frm) {
var dca = 0;
$.each(frm.doc.payment_details, function(i, d) {
dca += flt(d.…
Hi @msiam ,
Please apply custom/client script.
frappe.ui.form.on('Sales Invoice', {
validate: function(frm) {
ttl_itms_dicnt = 0;
$.each(frm.doc.items, function(i, d) {
ttl_itms_dicnt += flt(d.discount_amount);
});
frm.doc.total_items_discount = ttl_itms_dicnt;
}
});
Please check your field name and set it according.
Then reload and check it.
Thank You!
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.
NCP
May 30, 2023, 8:05am
4
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!
1 Like
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”.
NCP
May 30, 2023, 8:42am
6
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
NCP
May 30, 2023, 8:55am
7
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