Library › Coding AI › Small business owners

Email yourself a low-stock list with Apps Script

Practice: Setting limits and rules. About 5 minutes.

About this exercise

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.

Common mistakes when you ask AI for this

  • Leaving the comparison vague. The AI uses below (<), so items sitting exactly at the reorder point are missed. Try: Add: "At or below Reorder at."
  • Not showing the email. The AI sends an HTML table or one email per item. Try: Add: "One plain-text email, subject Low stock, lines like CK-LAV8 - Lavender 8oz: 6 left. Nothing when none are low."
  • Not ruling out extras. The AI adds trigger setup, logging and error handling you didn't ask for. Try: Add: "No trigger code, HTML, logging or try/catch."
  • Getting a menu of options. The AI likes to offer two or three versions of the script, so you're left to pick and test them yourself. Try: Add: "Give one script only, in one code block, no alternatives."
  • Getting a tutorial. By default the AI explains every part of the code at length, which you then have to scroll past. Try: Add: "After the code, one line under 12 words. Nothing else."

What a strong prompt includes

  • Says at or below
  • Shows a line of the email
  • Skips empty emails
  • Rules out extras
  • Caps the code length

Practice this now ↑

Related exercises