Valididation of No Duplication in Item Price

Hi,

I would like to validate that there is no duplication in Item Price. The parameters are Item Code, Price List and Batch No so I tried the following script but it seems doesn’t work as I am getting a false error that there is a duplication.

frappe.ui.form.on("Item Price", "validate", function(frm) {
if(frm.doc.__islocal)
frappe.call({
        method: "frappe.client.get_value",
        args: {
                doctype: "Item Price",
                fieldname: "name",
                filters: {
                        item_code: frm.doc.item_code,
			price_list: frm.doc.price_list,
			batch_no: frm.doc.batch_no
                }
        },
        callback: function(response) {
             var item_code = response.message;
             if (item_code) {
                  frappe.msgprint("The same item with the same price list & same batch no already exists");
			validated=false;
    			return false;
		
             }
        }
});
});

I followed the same example in this topic Validate Duplication on two fields - #4 by shahid

Can someone advise how to solve?

Regards,
Ahmed Sharaf

frappe.ui.form.on("Item Price", "validate", function(frm) {
    frappe.call({
        method: "frappe.client.get_value",
        args: {
                doctype: "Item Price",
                filters: {
                        item_code: frm.doc.item_code,
            			price_list: frm.doc.price_list,
            			batch_no: frm.doc.batch_no
                },
                fieldname:["item_code", "price_list", "batch_no"]
        },
        callback: function(r) {
            console.log(r);
             var price_list = r.message.price_list;
             var item_code = r.message.item_code;
             var batch_no = r.message.batch_no;
             if (price_list == frm.doc.price_list && item_code == frm.doc.item_code && batch_no == frm.doc.batch_no ) {
                frappe.msgprint("The same item with the same price list & same batch no already exists"); 
			   validated=false;
    			return false;
		
             }
        }
    });
});