Trying below filters but it seems they are not working and it only fetches the latest row updated in Item Price, kindly suggest: (selling_price_list is in Sales Order && item_code is in Sales Order Item)
I am missing the point here that I don’t know where to put while loop with frappe.call; and yes that would be good on Validate Trigger I guess. Kindly suggest.
Yes, I got the correct value using index, but it needs to be done with all the sales order items which are being inserted.
Tried below:
frappe.ui.form.on('Sales Order Item', 'item_code', function(frm, cdt, cdn){
var tbl = frm.doc.items || [];
var i = tbl.length;
while (i--) {
frappe.call({
method: "frappe.client.get_value",
args: {
doctype: "Item Price",
filters:
{ item_code: ["=", frm.doc.items[i].item_code], price_list: ["=", frm.doc.selling_price_list]},
fieldname: "stamount",
},
callback: function(r) {
frappe.model.set_value(cdt, cdn, "test_price", r.message.stamount);
frm.refresh_field("test_price");
}
});
});