Task guide
Email yourself a weekly sheet summary
Get a short email every Friday with the numbers from an Orders tab: how many rows it has, the total of column C, and how many rows are not Done. Run the setup function once to install the weekly trigger.
1 · Prepare
Put these pieces in place
- Open the script from the spreadsheet with Extensions, then Apps Script.
- Create a tab named Orders with headers in row 1 and the first data row in row 2.
- Put a number in column C for the amount and a status word in column D, such as Done.
- Use an account that can send email through Gmail.
Change these values
- Sheet name
OrdersThe tab the summary reads. It must already exist.
- Send day
ScriptApp.WeekDay.FRIDAYThe weekday the trigger runs. Other values look like ScriptApp.WeekDay.MONDAY.
- Send hour
16The hour the trigger runs, in the project time zone. 16 means some time between 4 PM and 5 PM.
- Finished status
DoneRows whose column D does not match this word exactly are counted as still open.
2 · Review before running
What the script can access and change
Permissions you approve
- See, edit, create, and delete all your Google Sheets spreadsheets. The code only reads the Orders tab and the link of this spreadsheet.
- Read, compose, send, and permanently delete all your email from Gmail. Google asks for full Gmail access because the code uses GmailApp, but the code only sends the summary to the account that installed the trigger.
- See your primary Google Account email address. The code reads it to know where to send the summary.
- Allow this application to run when you are not present. This lets the script install its weekly trigger and send the summary on schedule.
Effects of one run
- Sends one short plain text email each week to the account that installed the trigger.
- Reads the sheet only. No cell is written, moved, or deleted.
- Completely blank rows in columns A through D are ignored, while rows with a zero amount are still counted.
3 · Copy
Paste this into the Apps Script editor
Create or open a script file, replace the example values marked above, then save the project.
const SHEET_NAME = 'Orders'; // The tab the summary reads. It must already exist.
const SEND_DAY = ScriptApp.WeekDay.FRIDAY; // The weekday the trigger runs. Other values look like ScriptApp.WeekDay.MONDAY.
const SEND_HOUR = 16; // The hour the trigger runs, in the project time zone. 16 means some time between 4 PM and 5 PM.
const FINISHED_STATUS = 'Done'; // Rows whose column D does not match this word exactly are counted as still open.
function createWeeklySummaryTrigger() {
const alreadyInstalled = ScriptApp.getProjectTriggers().some((trigger) => {
return trigger.getHandlerFunction() === 'sendWeeklyOrderSummary';
});
if (alreadyInstalled) return;
ScriptApp.newTrigger('sendWeeklyOrderSummary')
.timeBased()
.onWeekDay(SEND_DAY)
.atHour(SEND_HOUR)
.create();
}
function sendWeeklyOrderSummary() {
const spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
const sheet = spreadsheet.getSheetByName(SHEET_NAME);
if (!sheet) throw new Error('Add a Sheet tab named ' + SHEET_NAME + ' before running this function.');
let rowCount = 0;
let total = 0;
let notDone = 0;
const lastRow = sheet.getLastRow();
if (lastRow >= 2) {
const rows = sheet.getRange(2, 1, lastRow - 1, 4).getValues();
const dataRows = rows.filter((row) => row.some((cell) => cell !== ''));
rowCount = dataRows.length;
dataRows.forEach((row) => {
const amount = Number(row[2]);
if (!isNaN(amount)) total = total + amount;
if (String(row[3]).trim() !== FINISHED_STATUS) notDone = notDone + 1;
});
}
const reportDate = Utilities.formatDate(new Date(), Session.getScriptTimeZone(), 'yyyy-MM-dd');
const lines = [
'Orders summary for ' + reportDate,
'Rows with data: ' + rowCount,
'Total amount: ' + total,
'Not marked ' + FINISHED_STATUS + ': ' + notDone,
spreadsheet.getUrl()
];
GmailApp.sendEmail(Session.getEffectiveUser().getEmail(), 'Weekly orders summary', lines.join('\n'));
} 4 · Run
Follow these steps in order
Set up the Orders tab
Put headers in row 1 and a few test rows from row 2 down. Column C holds the amount as a number, and column D holds the status word, such as Done.
Run the summary by hand first
Choose Extensions, then Apps Script. Paste both functions over the starter code and save. Choose sendWeeklyOrderSummary in the function dropdown above the code, then click Run. Approve access when Google asks, then compare the numbers in the email with the sheet.
Install the weekly trigger
When the numbers look right, choose createWeeklySummaryTrigger and click Run once. It does nothing when a trigger for sendWeeklyOrderSummary already exists, so running it twice does not add a second trigger.
Check the trigger list
Click Triggers, the clock icon in the left sidebar. sendWeeklyOrderSummary is listed as a week timer for Friday. The trigger runs as the account that created it, and that is the account the summary is sent to.
5 · Confirm
How to tell it worked
An email with the subject Weekly orders summary lists the report date, how many data rows the tab has, the total of column C, how many rows are not Done, and a link to the spreadsheet.
If the result is different
Troubleshooting
- The run stops with "Add a Sheet tab named Orders before running this function."
- Rename the tab to Orders, or change SHEET_NAME in the code to the name of your tab. The name has to match exactly, including capital letters.
- The total is 0 even though column C has values.
- Remove any text from the amount cells, such as 1,200 USD, and leave plain numbers. A cell holding text is skipped. Use Format, Number, Currency if you want a currency sign.
- Every row is counted as not Done.
- Use the same spelling of Done in every row of column D, or change FINISHED_STATUS to the word you use. Spaces around the word are ignored, but done and Done are different.
- No email arrives on Friday.
- Open Executions in the left sidebar to see whether the trigger ran and what it reported. The hour follows the project time zone, which you can check under Project Settings, the gear icon.
Technical details
Names used in this script
Open these details when you want to adapt the example or look up an exact service or method name.
Show Apps Script symbols and service pages
Apps Script symbols
Service pages
Keep going
Related tasks, basics, and apps
- Task guide Run an Apps Script function every day
Make a function run on its own once a day. Run the setup function once, and from then on Apps Script calls the reminder function each day around the hour you chose.
- Task guide Back up a spreadsheet to Drive every week
Keep a dated copy of a spreadsheet in a Drive folder. Run the setup function once, and every Monday morning the script saves a new copy with the date in its name.
- Task guide Send an email for each row in a Google Sheet
Send one email to each person listed on a Customers tab. The script marks each row Sent as it goes, so a later run sends only to rows that are not marked yet.
- Object reference Trigger builder
ScriptApp.newTrigger(functionName) returns a TriggerBuilder that configures a timeBased(), forSpreadsheet(), or forForm() trigger before create() saves it.
- Object reference Spreadsheet
A Spreadsheet is the whole Google Sheets file. Use SpreadsheetApp.getActiveSpreadsheet() or openById() to get it, then call getSheetByName() or getActiveSheet().
- Object reference Sheet
A Sheet is one tab inside a Google spreadsheet. Get it with getSheetByName() or getActiveSheet(). Use getLastRow() to find the last row with content, or getRange() to select cells to read.
- Basics Google Apps Script triggers explained
Google Apps Script triggers run functions automatically when a file opens, a cell changes, a form is submitted, or a scheduled time arrives. Use a simple onEdit or onOpen for work in the bound file. Choose an installable trigger for a schedule, form submission, or work that needs authorization.
- Google app Google Sheets
SpreadsheetApp lets a Google Sheets script read a Sheet or Range, add a custom menu or formula, and act on each row, such as sending one email per row.
- Google app Gmail
GmailApp scripts can send messages, search threads, apply labels, and read attachments after you approve Gmail access for the project.
- Google app Triggers
A trigger is a saved schedule or event rule in ScriptApp that runs your function on time, on edit, or on form submit.