-
Notifications
You must be signed in to change notification settings - Fork 0
/
google_sheet_reminder.js
55 lines (45 loc) · 2.01 KB
/
google_sheet_reminder.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
function send_schedule_email_reminder() {
// This first part of reading the contents can be abbrieviated probably
var startHeaderRow = 3;
var lastColumn = 12;
var startContentRow = 4;
var sheet = SpreadsheetApp.getActiveSheet();
var header = sheet.getRange(startHeaderRow, 1, 1, lastColumn).getValues();
// Read in header based on startHeaderRow, lastColumn
//Ref: https://developers.google.com/apps-script/reference/spreadsheet/sheet#getRange(Integer,Integer,Integer,Integer)
var numRows = sheet.getDataRange().getNumRows(); // Get total number rows
var dataRange = sheet.getRange(startContentRow, 1, numRows, lastColumn);
var data = dataRange.getValues();
var emailAddress = "[email protected]";
var emailSubject = "Name_your_email_subject";
var emailContent = "Add_introduction_text_in_email";
var currentDate = new Date(); // Get current date
var selectedRow;
// Loop through the sheet for date within the next 7 days
for (var l in data) {
var row = data[l];
selectedRow = row;
var dateSchedule = row[0];
Logger.log(dateSchedule);
var differenceInMillis = currentDate.getTime() - dateSchedule.getTime();
var daysDiff = Math.floor(differenceInMillis / 1000 / 60 / 60 / 24);
if ((daysDiff <= 0) && (daysDiff >= -7)) {
break;
}
}
emailSubject += selectedRow[0].toDateString(); // Add date to subject
// Add each column in the selectedRow of this found date, i.e., collect all fields
emailContent += selectedRow[0].toDateString() + "\n\n"; // Add date to content
// Collect all fields in var content
var content = "\t";
for (var i = 1; i < 11; i++) {
content += header[0][i] + ": " + selectedRow[i] + "\n\t";
}
emailContent += content;
emailContent += "Add_last_paragraph_of_the_email. You can also insert the hyperlink of the shared google sheet document.";
MailApp.sendEmail(emailAddress, emailSubject,
emailContent, {
cc: "[email protected]"
});
//cc is an option: string with comman seperated email addresses
}