Need Help - Custom script to fetch item price in Opportunity Item Table

Hello,

I have created a custom fields “Rate” and “Amount” in the Opportunity Item. I’m trying to fetch the item price for a particular item code from the Item Price doctype by using the below script. The value fetches, but the problem is, when i enter an item code, the rate field doesn’t display anything, but when i expand the table row the value shows in the field. Even when i minimize the row the value display back even in the list view.

Can anyone please help with this issue.

Please see the screenshots and scripts;

Custom Script: Found this script in forum search

frappe.ui.form.on(“Opportunity Item”,
{
item_code: function(frm, cdt, cdn)
{
var d = locals[cdt][cdn];
frappe.call(
{
method: “frappe.client.get_value”,
args: {
doctype: “Item Price”,
filters: {
price_list: “Standard Selling”,
item_code: d.item_code,
item_group: d.item_group
},
fieldname:[“price_list_rate”]
},
callback: function®
{
if(r.message)
{
var item_price = r.message;
frm.set_value(d.rate = item_price.price_list_rate);
}
}
});
}
})