{"id":"code-work-sb-apps-script-low-stock-email","audience":"small-business","category":"coding","track":"coding","technique":"constraints","title":"Email yourself a low-stock list with Apps Script","free":false,"task":"Write a Google Apps Script function named checkLowStock that reads the tab named Inventory and emails bea@copperkettle.example one plain-text email with the subject Low stock, listing every item whose On hand (C) is at or below Reorder at (D), one line each like CK-LAV8 - Lavender 8oz: 6 left. Send nothing when no items are low. Bea will add the daily trigger by hand, so no trigger code, no HTML, logging or try/catch. One code block, at most 16 lines, then under 25 words outside the code.","materialLabel":"Inventory tab preview (attached to your prompt automatically)","material":"INVENTORY tab - Copper Kettle Candle Co. (row 1 is headers)\nA Item | B SKU | C On hand | D Reorder at | E Supplier\nLavender 8oz | CK-LAV8 | 6 | 10 | Wickworks\nCedar 16oz | CK-CED16 | 22 | 12 | Wickworks\nWick trimmer | CK-TRIM | 4 | 4 | Hollow Tools\nSampler box | CK-SAMP | 15 | 8 | in-house\nGift card | CK-GIFT | 999 | 0 | digital\n\nNotes from Bea:\n- I check this by hand most mornings and forget on busy days.\n- Wickworks needs about 5 business days to deliver.\n- The tab has around 60 items.\n- There's also a Sales tab and a Suppliers tab in the same file.\n- My phone shows emails as plain text anyway.","rules":[{"type":"codeBlocks","count":1},{"type":"maxCodeLines","max":16},{"type":"maxProseWords","max":25}],"mistakes":[{"title":"Leaving the comparison vague","why":"The AI uses below (<), so items sitting exactly at the reorder point are missed.","fix":"Add: \"At or below Reorder at.\"","checks":["r0"]},{"title":"Not showing the email","why":"The AI sends an HTML table or one email per item.","fix":"Add: \"One plain-text email, subject Low stock, lines like CK-LAV8 - Lavender 8oz: 6 left. Nothing when none are low.\"","checks":["r1"]},{"title":"Not ruling out extras","why":"The AI adds trigger setup, logging and error handling you didn't ask for.","fix":"Add: \"No trigger code, HTML, logging or try/catch.\"","checks":["r2","maxCodeLines"]},{"title":"Getting a menu of options","why":"The AI likes to offer two or three versions of the script, so you're left to pick and test them yourself.","fix":"Add: \"Give one script only, in one code block, no alternatives.\"","checks":["codeBlocks","maxCodeLines"]},{"title":"Getting a tutorial","why":"By default the AI explains every part of the code at length, which you then have to scroll past.","fix":"Add: \"After the code, one line under 12 words. Nothing else.\"","checks":["maxProseWords"]}],"promptHints":[{"label":"Says at or below","patterns":["at or below","<=","or equal"]},{"label":"Shows a line of the email","patterns":["ck-lav8","left","subject"]},{"label":"Skips empty emails","patterns":["nothing when","no items|none are low","only (send|if)"]},{"label":"Rules out extras","patterns":["no (trigger|html|logging|try)","try/catch"]},{"label":"Caps the code length","patterns":["\\d+\\s*lines","at most","under \\d+","short"]}],"hint":"Tell the AI exactly what the email looks like, when not to send it, and what it shouldn't add.","rubricLabels":["Is a function named checkLowStock that reads the tab by name (getSheetByName(\"Inventory\")), skips the header row and picks items where column C is at or below column D (<=), so the Wick trimmer at 4 of 4 is included","Builds one line per item shaped SKU - Item: N left (like CK-LAV8 - Lavender 8oz: 6 left) and sends a single MailApp or GmailApp email to bea@copperkettle.example with the subject Low stock only when the list isn't empty","Has no trigger code (ScriptApp.newTrigger), no htmlBody, no Logger.log or console.log and no try/catch"]}