Frappe.get_doc from "Bin" is throwing error

Hi,

Though I have stock in the warehouse for the item, while executing the following code in Client Script it is throwing error:

bin_doc = frappe.get_doc(“Bin”, filters={“item_code” : doc.item_code, “warehouse” : doc.warehouse}) ;
frappe.model.set_value(cdt, cdn, ‘stock_qty’, bin_doc.actual_qty);

Error Message:

*** ERROR *** //Cannot read properties of null (reading ‘actual_qty’)

Is anything wrong with my code?

Hy @pjoseph

If you want to get Actual Qty from bin doctype then this code will help you

	    frappe.db.get_value("Bin", {"item_code" : frm.doc.item_code, "warehouse" : frm.doc.warehouse}, "actual_qty", function(value) {
	        console.log("*********************",value)
	    })

Thank You!

Thanks a lot Mohammad. the following code works :

            frappe.db.get_value("Bin", {"item_code" : frm.doc.item_code, "warehouse" : frm.doc.warehouse}, "actual_qty", 
                function(value) 
                        { 
                            frappe.model.set_value(cdt, cdn, 'stock_qty', value.actual_qty); 
                        }) ;

@pjoseph If you find my code correct then you can give a solution mark to my post
Thank You!

value.actual_qty

This is working code:

        try {
                var mtl = locals[cdt][cdn];

                frappe.db.get_value("Bin", {"item_code" : mtl.item_code, "warehouse" : frm.doc.warehouse}, ["actual_qty","valuation_rate","stock_value","stock_uom"],
                    function(value) 
                            { 
                                frappe.model.set_value(cdt, cdn, 'stock_qty', value["actual_qty"]); 
                                frappe.model.set_value(cdt, cdn, 'rate',      value["valuation_rate"]); 
                                frappe.model.set_value(cdt, cdn, 'stock_val', value["stock_value"]); 
                                frappe.model.set_value(cdt, cdn, 'uom',       value["stock_uom"]); 
                            }) ;
        }

Thanks a lot @Mohammadali for providing the alternate logic and syntax (frappe.db.get_value).
We used it in our script.