Getting null from frappe.get_doc

trying:

$.each(recipeTable, function(index, row){
	qty = row.var_quant / 100;
	material = row.cat_num;
	materialType = "Raw material";
	priceDataSource = frappe.get_doc(materialType,material);
	alert(priceDataSource);
	price = priceDataSource.var_price;
	alert(price);
	total_price = total_price + price * qty;
});

and getting null in the priceDataSource variable
any idea what I’m doing wrong?
obviously “Raw material” is a viable DocType and the required “material” exist…

you can use this API on py files only
you can here use frappe call to call a python function

2 Likes

thanks found my stupidity already, but stuck on something even worse:
used:

	frappe.db.get_value(materialType,material,'var_price')
	.then(r => {
	    console.log(r.message.var_price);
        price = r.message.var_price;
});
//	alert("Updated");
	total_price = total_price + price * qty;

but without the alert("Updated"); “total_price” is 0!!
what am I missing?

try to put this line inside the returned callback value so you can catch it

tried it,
it didn’t work.
but I managed to workaroud by leaving the alert out of the $.each loop, thus causing the final set_value call to update correctly (can’t understad why…)