Mathematical Operations

@max_morais_dmm Still not working, and I’m not sure where I’m going wrong here.

Show me your code, it will be util to help you!

frappe.ui.form.on("Quotemaster Area", "len", function(frm, cdt, cdn){
  var d = locals[cdt][cdn];
  frappe.model.set_value(d.doctype, d.name, "area", d.len * d.wid);
});

frappe.ui.form.on("Quotemaster Area", "wid", function(frm, cdt, cdn){
  var d = locals[cdt][cdn];
  frappe.model.set_value(d.doctype, d.name, "area", d.len * d.wid);
});

@cpurbaugh do you have any message in browser console? Press F12 to check this!

The only thing that comes up is this:

unreachable code after return statement

Maybe the value already are in the field, but it’s not refreshing let’s try tp force the field refresh on screen.

add this stretch of code, below frappe.model.set_value

frm.fields_dict["grid-field-name"].grid.grid_rows_by_docname[cdn].area.refresh();

replace the grid-field-name by the name of the Table Field of Quotemaster Area

It’s not clear to me what you said in the last line there, but in the “Quotemaster” doctype, the “Quotemaster Area” table name is “area”. So, I put that. No change in result…

frappe.ui.form.on("Quotemaster Area", "len", function(frm, cdt, cdn){
  var d = locals[cdt][cdn];
  frappe.model.set_value(d.doctype, d.name, "area", d.len * d.wid);
  frm.fields_dict["area"].grid.grid_rows_by_docname[cdn].area.refresh();
});

frappe.ui.form.on("Quotemaster Area", "wid", function(frm, cdt, cdn){
  var d = locals[cdt][cdn];
  frappe.model.set_value(d.doctype, d.name, "area", d.len * d.wid);
frm.fields_dict["area"].grid.grid_rows_by_docname[cdn].area.refresh();
});

@cpurbaugh can you give me print-screen of your console?

@cpurbaugh :construction_worker: have something very strange in your code!

I’ll be greath if you share the full custom scripts for we undestand what is going wrong!

Unreachable code after return statement

Never sounds like a good thing!

That is the full script…Also, it says unreachable code after return statement on all pages, even at the desk.

@cpurbaugh this code looks nice! But if you have modifications in frappe code or ERPNext code, will be great if you check, because the messages in your console are causing your issue.

I don’t have any customizations in the source code at all, and this is my only custom script…

@cpurbaugh So, try update ERPNext and frappe, and check if the message still!

Some cases, certain extensions in the browser can cause strange errors too.

Will try update tomorrow. Also, Microsoft Edge gives this error:

These error is from WebSocket, nothing to worry at all!

You environment is not properly configured!

The most important is: The code works on Edge?

It does not. What’s wrong with the environment?

@cpurbaugh: Have a look at this thread

@Eli, The script from that thread works when I make the Quotemaster Area a master doctype instead of a child table. however, it does not work as a child table.

frappe.ui.form.on("Quotemaster Area", "wid", function(frm) {
       cur_frm.set_value("area", (frm.doc.wid * frm.doc.len));
       msgprint(frm.doc.wid);
});
frappe.ui.form.on("Quotemaster Area", "len", function(frm) {
       cur_frm.set_value("area", (frm.doc.wid * frm.doc.len));
       msgprint(frm.doc.len);
});
frappe.ui.form.on("Quotemaster Area", "area", function(frm) {
       cur_frm.set_value("area", (frm.doc.wid * frm.doc.len));
       msgprint(frm.doc.area);
});

@max_morais_dmm The following code also works when it’s a master doctype:

frappe.ui.form.on("Quotemaster Area", "len", function(frm, cdt, cdn){
  var d = locals[cdt][cdn];
  frappe.model.set_value(d.doctype, d.name, "area", d.len * d.wid);
  frm.fields_dict["area"].grid.grid_rows_by_docname[cdn].area.refresh();
});

frappe.ui.form.on("Quotemaster Area", "wid", function(frm, cdt, cdn){
  var d = locals[cdt][cdn];
  frappe.model.set_value(d.doctype, d.name, "area", d.len * d.wid);
frm.fields_dict["area"].grid.grid_rows_by_docname[cdn].area.refresh();
});

Even the very first formula I tried works now:

// add a trigger on field "len"       
    cur_frm.cscript.len = function(doc, cdt, cdn) {
          // update a new field "area"
     
      doc.area = flt(doc.len)*flt(doc.wid); 
         
      // refresh in form
          
      refresh_field('area');
          }
  
    
    // add the same trigger on "wid"
  
  
    
    cur_frm.cscript.wid = cur_frm.cscript.len;
1 Like

@cpurbaugh, In my case this worked even keeping the doctype as child table

frappe.ui.form.on(“Packing Materials”, “ordered”, function(frm,cdt,cdn) {
var d = locals[cdt][cdn];
frappe.model.set_value(d.doctype, d.name, “amount”, d.rate * d.ordered);
frm.fields_dict[“amount”].grid.grid_rows_by_docname[cdn].amount.refresh();
alert(frm.doc.amount);
});