# I want to calculate and display a value from one of the custom fields i have creatd

I have created 3 custom fields in the Doc Item for CBM calculation. Where in when i enter the height/ width / length it calculates and displays the CBM value instantly. The CBM here is based on the dimensions of the box of that particular item. Now what i want to do is to display this CBM value in the stock entry detail doc (item details Section) where in it will multiply it with the number of items in the stock i.e the Quantity and for UOM as box. And these values should be automatically updates based on the plus / minus in the stock quantity. So lets say if the total cbm for item X is H=10 W=12 and L= 13 so the total CBM will be HxWxL/1000000 = 0.001560000. So in the stock lets say i add entry for item X i.e 15 box so the Stock CBM will be - (Item.total_cbm) 0.001560000 x Stock Qty i.e 15 = 0.0234. so lets say i issue 2 boxes out of 15 to a customer then the Stock cbm value also should update. so the calculation will be 0.001560000 x 13 box = 0.02028. so based on the stock value it should update the stock cbm. Kindly let me know how to achieve this.

Also for the Total CBM calculation in the ITEM doc i am using below script:

frappe.ui.form.on(“Item”, “length”, function(frm) {
total_cbm(frm);
});

frappe.ui.form.on(“Item”, “width”, function(frm) {
total_cbm(frm);
});

frappe.ui.form.on(“Item”, “height”, function(frm) {
total_cbm(frm);
});

var total_cbm = function(frm) {
var total_cbm = flt(frm.doc.length) * flt(frm.doc.width)* flt(frm.doc.height) / 1000000;
frm.set_value(“total_cbm”, total_cbm);
}