I am trying to fetch the price_list_rate of an item and display it in the barcode I Am printing.
Here is what I tried and did not work:
body { max-height: 96px; /* 1 inch */ max-width: 192px; /* 2 inches */ overflow: hidden; display: flex; flex-direction: column; justify-content: center; align-items: center; margin: 0; text-align: center; } .item-info { font-size: 11px; /* Smaller font size for info */ }<script>
document.addEventListener("DOMContentLoaded", async function () {
const barcodeValue = "{{ doc.barcodes[0].barcode }}"; // Ensure this path is correct
const itemName = "{{ doc.item_name }}";
const itemCode = "{{ doc.item_code }}"; // Ensure we fetch item code correctly
// Generate the barcode
JsBarcode("#barcode", barcodeValue, {
format: "CODE128",
lineColor: "#000000",
width: 1.4, // Adjust the width for better barcode thickness
height: 35, // Set the height of the barcode
displayValue: true,
fontSize: 10, // Adjust font size for the item info
});
try {
// Specify your price list name
const priceList = "Standard Selling";
// Correctly structure the query
const filters = { item_code: itemCode, price_list: priceList };
// Fetch the selling price for the specific item and price list
const result = await frappe.db.get_value("Item Price", filters, "price_list_rate");
// Check if result is valid and extract the price
const itemPrice = result && result.price_list_rate ? result.price_list_rate : "N/A"; // Fallback if price not found
// Display the item information
const itemInfo = `
${itemName} <br>
$${itemPrice} <br>
`;
document.getElementById("item-info").innerHTML = itemInfo;
} catch (error) {
console.error("Error fetching item price:", error);
document.getElementById("item-info").innerHTML = `
${itemName} <br>
$N/A <br>
`;
}
});
</script>
Could someone please help me figure out why the try block is always catching error?