1
Create a new Google Sheet. Name the first sheet tab Inventory. Set up columns: A = section, B = paper name, C = max, D = qty.
2
Go to Extensions → Apps Script. Delete any existing code and paste the script below.
const SHEET_NAME = "Inventory";
function doPost(e) {
try {
const data = JSON.parse(e.postData.contents);
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheetByName(SHEET_NAME);
const values = sheet.getDataRange().getValues();
for (let r = 0; r < values.length; r++) {
for (let c = 0; c < values[r].length; c++) {
const cell = String(values[r][c]).trim();
const searchName = String(data.name || '').trim();
if (cell === searchName || cell.includes(searchName)) {
sheet.getRange(r + 1, 4).setValue(data.qty);
return ContentService
.createTextOutput(JSON.stringify({ status: "ok", row: r + 1 }))
.setMimeType(ContentService.MimeType.JSON);
}
}
}
return ContentService
.createTextOutput(JSON.stringify({ status: "not_found" }))
.setMimeType(ContentService.MimeType.JSON);
} catch(err) {
return ContentService
.createTextOutput(JSON.stringify({ status: "error", message: err.toString() }))
.setMimeType(ContentService.MimeType.JSON);
}
}
3
Click Deploy → New deployment. Type: Web app. Execute as: Me. Who has access: Anyone. Click Deploy.
4
Copy the Web app URL and paste it in the field above.