Refresh button not working - need help

Hi Guys ,

I have a refresh button to refresh the data in a particular field , but that is not working . Can anyone help me please

frappe.ui.form.on("Quotationmaster", "but", function(frm) {
  frm.refresh_field("fw")
});

Looks right. What are you trying to do ? try console.log and check if the function is being invoked.

What is the doctype name ? “Quotationmaster” looks wrong,

1 Like

Hi @neilLasrado ,

Many thanks for the reply , I have a doctype Quotationmaster where I will calculate the cost break up of a product I have numerous scripts in this doc and everything works like a charm , I have a field in “fw” , on changing this field the entire script runs again and the whole calculation is recalculated , so everytime I should manually change the value of this field “fw” and put back by old value if I want to alter some others manual input fields , so to overcome this , I tried adding a button to manually refresh this “fw” so that without changing the value of this “fw” field I would rerun my calculation ,

Please help , below is my script to rerun the calculation I should refresh fw field

{
function compute(doc, cdt, cdn){
    if (doc.hlop && doc.fla && doc.fw && doc.ebwa && doc.cla && doc.landed && doc.sr && doc.pos && doc.rmsec && doc.rminvper && doc.wipinvper && doc.icc && doc.cpdays && doc.pfc){ 
doc.hl = doc.fw * (doc.hlop/100);
doc.fl = doc.fw * (doc.fla/100);
doc.cmw = doc.fw + doc.hl + doc.fl;
doc.ebwkg = doc.cmw * (doc.ebwa/100);
doc.clkg = doc.cmw * (doc.cla/100);
doc.imwtkg = doc.ebwkg + doc.clkg + doc.cmw;
doc.imc = doc.imwtkg * doc.landed;
doc.sc = (doc.fl + doc.clkg + doc.ebwkg) * (doc.sr/100) * doc.pos ;
doc.nmc = doc.imc - doc.sc ;
doc.cut = ((doc.rmsec * doc.rmsec )/100) * doc.cost;
doc.foc = doc.cmw * doc.forskg;
doc.pow = doc.cmw * doc.prskg;
doc.dlc = doc.cmw * doc.dl;
doc.admin = doc.adm * doc.cmw;
doc.fetl = doc.fw * doc.fet;
doc.shot = doc.fw * doc.sb;
doc.np = doc.pnidpp;
doc.tpc = doc.cut + doc.foc + doc.pow + doc.dlc + doc.admin + doc.fetl + doc.shot + doc.np + doc.htco + doc.pfc;
doc.iccrmwipcr = (doc.nmc * (doc.rminvper/30) * ((doc.icc/100)/12))+((doc.nmc + doc.tpc) * ((doc.cpdays + doc.wipinvper)/30) * ((doc.icc/100)/12));
doc.pnoh = (doc.nmc + doc.tpc) * (doc.poh/100);
doc.twippoh = doc.pnoh + doc.iccrmwipcr;
doc.bcppc = doc.nmc + doc.tpc + doc.twippoh;
doc.dac = doc.amor;
doc.standard_rate = doc.bcppc + doc.dac;
doc.bcpkg = doc.standard_rate/doc.imwtkg;
refresh_field("hl");
refresh_field("fl");
refresh_field("cmw");
refresh_field("ebwkg");
refresh_field("clkg");
refresh_field("imwtkg");
refresh_field("imc");
refresh_field("sc");
refresh_field("nmc");
refresh_field("cut");
refresh_field("foc");
refresh_field("pow");
refresh_field("dlc");
refresh_field("admin");
refresh_field("fetl");
refresh_field("shot");
refresh_field("np");
refresh_field("tpc");
refresh_field("iccrmwipcr");
refresh_field("pnoh");
refresh_field("twippoh");
refresh_field("bcppc");
refresh_field("standard_rate");
refresh_field("bcpkg");
refresh_field("dac");
    }}
cur_frm.cscript.custom_hlop = compute;
cur_frm.cscript.custom_fla = compute;
cur_frm.cscript.custom_fw = compute;
cur_frm.cscript.custom_ebwa = compute;
cur_frm.cscript.custom_cla = compute;
cur_frm.cscript.custom_landed = compute;
cur_frm.cscript.custom_sr = compute;
cur_frm.cscript.custom_pos = compute;
cur_frm.cscript.custom_rmsec = compute;
cur_frm.cscript.custom_rminvper = compute;
cur_frm.cscript.custom_wipinvper = compute;
cur_frm.cscript.custom_icc = compute;
cur_frm.cscript.custom_cpdays = compute;
cur_frm.cscript.custom_dac = compute;
cur_frm.cscript.custom_pfc = compute;
}

Thanks

You can call the on_change function of field “fw” on click of the button.

frappe.ui.form.on("doctype", "fieldname_of_button", function(frm, cdt, cdn) {
	frappe.ui.form.trigger("doctype", "fw");
});
1 Like

@nabinhait . It works like a charm . Thank you so much

Hi @nabinhait . I have one more doubt can I use the same button to call the on_change function of more than one field ?

Thanks

Yes, you can unless those functions does not have server call. If they have server call, then it can cause issue due to asynchronous behaviour of javascript.

1 Like

Yes , thanks for the clarification @nabinhait . This thread can be closed .