Field that sum 2 fields that will be used on reports

Hi,

What I am trying to achieve is
1.) to get total weight by multiplying weight per unit in Item master to actual quantity in stock ledger, 2.)Use the Total Weight on a custom report

I managed to do no.1 with a custom script however when I fetch the field for my report it shows 0 it seems that custom script does not interact with the data base.

can you show your code? You may have missed some commit commands

frappe.ui.form.on(“Stock Ledger Entry”,“onload”,function(frm, cdt, cdn){
var d = locals[cdt][cdn];
console.log(“d” + d);
frappe.model.set_value(cdt, cdn, “total_weight”, d.weight_per_unit * d.actual_qty);
frm.refresh_field(“total_weight”);
});

this is the custom script I used to do my calculations

Try to debug by placing a debugger statement in your code so you can step through your code.
Also, add more console.log statement to check the values of your variables (objects).
I think I see the “fish”. But I think it is better to give you “fishing tips” first.

Did I miss anything? and Can a custom script insert field data to the database to be used on reports?

Column in the report are still empty
Ps. Even in the list view it is empty

frappe.ui.form.on(“Stock Ledger Entry”,“onload”,function(frm, cdt, cdn){ var d = locals[cdt][cdn]; console.log("d: ", d); frappe.model.set_value(cdt, cdn, “total_cbm”, d.weight_per_unit * d.actual_qty); frm.refresh_field(“total_cbm”); });

frappe.ui.form.on(‘Stock Ledger Entry’, ‘refresh’, function(frm){ var a = 123; console.log("a: ", a); cur_frm.set_value(“total_cbm”, a); });

Solved this by just saving the document afterwards