File size: 1,317 Bytes
a4dde79
 
 
1b41119
a4dde79
 
 
 
 
 
 
d6db1fb
a4dde79
 
 
 
 
1b41119
a4dde79
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
window.onload = async function () {
    const queryParams = new URLSearchParams(window.location.search);
    const itemDescription = queryParams.get('itemDescription');
    // alert("item: " + itemDescription)
    if (!itemDescription) {
        alert("No item description provided!");
        return;
    }

    try {
        // Fetch data from the Google Sheets API or your backend
        const response = await fetch(`https://iacelectricals-backendrmitem.hf.space/items?description=${encodeURIComponent(itemDescription)}`);
        if (!response.ok) {
            throw new Error("Failed to fetch item details.");
        }

        const data = await response.json();
        // alert("data " + data)
        // Populate the fields with the data
        document.getElementById('item-description').value = data.ItemDescription || "N/A";
        document.getElementById('item-code').value = data.ItemCode || "N/A";
        document.getElementById('current-balance').value = data.CurrentBalance || 0;
        document.getElementById('unit').value = data.Unit || "N/A";
        document.getElementById('google-form-link').href = data.GoogleFormLink || "#";
    } catch (error) {
        console.error("Error fetching item details:", error);
        alert("Error fetching item details. Please try again.");
    }
};