Free resource
Free Google Sheets Low Stock Alert Script
A free Apps Script that emails you when stock in Google Sheets drops to its reorder level. Copy the code, set it up in 10 minutes, no monthly fee. It runs in your own Google account.
Set it up
- Make a tab named Stock with five columns in this order: Product, Stock, Reorder level, Status, Alert. Leave Alert empty: the script writes the date there so you don't get the same email every hour.
- Open Extensions > Apps Script, delete what's in the editor, paste the code and put your own email in email:. Save.
- Pick setup from the function list and click Run.
- Google asks for permission: Review permissions, choose your account, then Advanced > Go to (your project). It's your own script, in your own account.
- Tick Select all, then click Continue. The boxes start unchecked; if you skip them the script can't send email. To test, lower a product's stock and run checkStock.
The full script
// Emails you when stock runs low. Columns: Product | Stock | Reorder level | Status | Alert
const CONFIG = {
sheet: 'Stock',
email: 'you@example.com',
};
function checkStock() {
const sheet = SpreadsheetApp.getActive().getSheetByName(CONFIG.sheet);
const rows = sheet.getDataRange().getValues();
const lowItems = [];
for (let i = 1; i < rows.length; i++) {
const [product, stock, reorderLevel, , alerted] = rows[i];
if (!product || stock === '') continue; // skip blank rows and items with no stock count yet
const cell = sheet.getRange(i + 1, 5);
if (stock <= reorderLevel && !alerted) {
lowItems.push(`${product}: ${stock} left (reorder level: ${reorderLevel})`);
cell.setValue(new Date());
} else if (stock > reorderLevel && alerted) {
cell.clearContent();
}
}
if (lowItems.length) {
MailApp.sendEmail(CONFIG.email, `Low stock alert (${lowItems.length})`, lowItems.join('\n'));
}
}
function setup() {
// Remove only this script's old hourly trigger, never your other triggers.
ScriptApp.getProjectTriggers()
.filter((t) => t.getHandlerFunction() === 'checkStock')
.forEach((t) => ScriptApp.deleteTrigger(t));
ScriptApp.newTrigger('checkStock').timeBased().everyHours(1).create();
}
Common mistakes
- Cannot read properties of null (reading 'getDataRange').
- The script can't find your tab. Rename the tab to exactly Stock, or change sheet: in the code.
- An error about permission for MailApp.sendEmail.
- You clicked Continue without ticking the boxes. Run setup again and tick Select all this time.
- No email arrived.
- Check four things: the Alert cell for that product is empty (a date there means you were already alerted), the stock is really at or below the reorder level, Stock and Reorder level are plain numbers (not text like "3 pcs") and every product has a reorder level, and your spam folder.
- Why not an onEdit trigger?
- Simple triggers like onEdit can't send email, and they don't fire when stock changes come from an import, an app or another script. A time-based trigger catches both.
- What's the right reorder level?
- Average daily sales x supplier lead time in days, plus a safety buffer. Sell 4 a day, supplier takes 5 days: 4 x 5 = 20, plus 5 = 25.