Refresh field in child Table

I’m using below script to get an email address from child table (sales team) into filed in parent doc field called psemail it’s working fine but only when i manually change a value in child table not automatically when document load

frappe.ui.form.on(“Sales Team”, “email”, function(frm,cdt,cdn) {
var d = locals[cdt][cdn];
cur_frm.set_value(“spemail”,d.email);
cur_frm.refresh_fields(‘sales_team’);
});

any idea to make it work automatically wiht doc loading

looks like you should -

frm.refresh_field('spemail');

Thanks for your response but it’s not working do you have any other idea

@akurungadam,

You can use frm.refresh_field(“accounts”);

Uncaught (in promise) TypeError: me.refresh_field is not a function

@Alaa_Badri,
You can use frm.refresh_field(“accounts”);
Thanks

Dear @Solufy
what do you mean for

@Alaa_Badri.

You can use your field name instead of “accounts”.
.

i’m already did but not working

what happens is when I change sales person name in sales team table it’s working fine and i got the email id in spemail field in the parent doc Event but i need to get it automatically when i refresh the document or even when press save bottom

You have to do some code in the refresh event of the form. Maybe you should loop through the list and set the emails that you want.

Do you have any suggesting for this code

Maybe @Solufy can write something for you

@Alaa_Badri,

Please refer the below code for same.

frappe.ui.form.on(“Fee Charges Master”, “fee_amount_remove”, function(frm, cdt, cdn) {
// code for calculate total and set on parent field.
console.log(“::::frm:: delete:::”, frm.doc);
total_sum = 0;
$.each(frm.doc.fee_amount || [], function(i, d) {
total_sum += flt(d.amount);
console.log(“::::frm:: total_sum:::”, total_sum);
});
refresh_field(“total_amount”);
frm.set_value(“total_amount”, total_sum);
});

1 Like