Field not found

Hi, Why is that the field for our buying_cost_total kept getting errors. We would like to multiply the qty to the price_list_rate then show its product to buying_cost_total. Here’s the script

frappe.ui.form.on(“Bill of Materials Item”, “price_list_rate”, function(frm, cdt, cdn) {
// code for calculate total and set on parent field.
buying_cost_total = 0;
$.each(frm.doc.items || [], function(i, d) {
buying_cost_total = flt(d.price_list_rate * d.qty);
frm.set_value(“buying_cost_total”, buying_cost_total);

Please refer to the pictures.

@kelscey90 because your field is into a sub-record, and frm is a reference to the main form.

Instead of frm.set_value use frappe.model.set_value(cdt, cdn, "buying_cost_total", buying_cost_total);

1 Like

@max_morais_dmm Works great! But why is it that when I input the price and change the qty it won’t formulate? I tried inputting the price first then put the qty it wont show the product but if I do it vice versa. Like I put the qty first then the price it will formulate.

Because your function is binding only for price_list_rate, you need write a global function for that in the global namespace, and call in the bind of each field.

I apologize for I can’t seem to understand what you meant. Can you kindly show an example or elaborate more for my understanding? Thank you.

@kelscey90 frappe.ui.form.on receive 3 arguments, first is the doctype, 2nd is the field that will fire the event and the 3rd an function.

You only have this behavior listening for the changes on the field price_list_rate, do you need replicate the same function for the other fields that you know that when the user change it, it will change the value.