Client Script to fetch Purchase Rate of the Item in the Sales Invoice

Dear Awesome Team,

Once I select an Item in an Sales invoice, I want to display the Purchase price of the Item in one of the field (custom_purchase_price ) in the Sales Invoice Item Child Table in Sales Invoice.
(The Purchase Price shall be fetched from the Item Price Doctype, field : price_list_rate).

Below is Client Script:
frappe.ui.form.on(“Sales Invoice Item”, “item_code”, function(frm, cdt, cdn) {
var d = locals[cdt][cdn];
frappe.db.get_value(“Item Price”, {“name”: d.item_code}, “price_list_rate”, function(value) {
d.custom_purchase_price = value.price_list_rate;
});
});

But nothing is happening when I select an Item in Sales Invoice, Pls help us find out whats wrong?

Highly appreciate your support.

Because if we assume that item A has multiple price lists, it can be confusing to determine how to obtain them.

And also this is wrong.

you have to set like

{'item_code': d.item_code}

frappe.ui.form.on(“Sales Invoice Item”, “item_code”, function(frm, cdt, cdn) {
var d = locals[cdt][cdn];
frappe.db.get_value(“Item Price”, {“item_code”: d.item_code,“price_list”: “Standard Buying”}, “price_list_rate”, function(value) {
d.custom_purchase_price = value.price_list_rate;
});
});

Also, there is ONLY single Standard Buying price for chosen Item in Item Price

Now your code looks perfect.

blessings and cheers NCP, it has worked. Many Thanks again.