Google Sheets/Forms Script Due Date Reminder email Sends Wrong Response Edit Link - email

The system I set up does the following:
a user submits a form
a confirmation email is sent with a link to edit the response (so far so good)
in the form, there is a 'due date' question
a trigger script scans these dates each day
when the due date has come, it sends a reminder email (this also happens properly, but)
in this reminder email, the edit link is repeated, so that the user doesn't have to search for the previous mail
Sadly this link is sent out wrong. Instead of linking to the proper response, it gives the link to the response that has been edited (submitted) last.
Here is the script:
function sendReminderEmail() {
var sheet = SpreadsheetApp.getActiveSheet();
var startRow = 2; // First row of data to process
var numRows = sheet.getLastRow()-1; // Number of rows to process
// Fetch the range of cells A2:B3
var dataRange = sheet.getRange(startRow, 1, numRows, sheet.getLastColumn());
// Fetch values for each row in the Range.
var data = dataRange.getValues();
//Logger.log(data)
var form = FormApp.openById("IDremovedByMe");
var formResponses = form.getResponses();
var r = formResponses.length-1;
var editURL = formResponses[r].getEditResponseUrl();
//Get the Edit URL
for (i in data) {
var row = data[i];
var date = new Date();
date.setHours(0);
date.setMinutes(0);
date.setSeconds(0);
//Logger.log(date);
var sheetDate = new Date(row[13]);
//Logger.log(sheetDate);
var Sdate = Utilities.formatDate(date,'GMT+0100','yyyy:MM:dd')
var SsheetDate = Utilities.formatDate(sheetDate,'GMT+0100', 'yyyy:MM:dd')
Logger.log(Sdate+' =? '+SsheetDate)
if (Sdate == SsheetDate){
var sendTo = row[4]; // Collect email address from the fourth column (number value is always -1).
var sendMe = "xyzabcloremipsum#gmail.com"; // Enter the email address where you wish to receive a notification about a reminder sent.
var sendername = "Auto Formbot"; // Name displayed as the sender.
var myname = "Formbot"; // Name displayed as the sender to you.
var messageTo = "Based on the data you entered, the '" +row[6] +"' project with the ID: " +row[1] +" has ended.\n\nPlease mark it as 'Completed' and update the details as soon as it's convenient for you.\n\nYou can edit your data by using the following link:\n" + editURL + "\n\nThank you for your time.\n\n\nWith kind regards,\nFormbot";
var messageMe = "The '" +row[6] +"' project with the ID: " +row[1] +" has finished today.\n\nA reminder email has been sent to " +row[4] +".\n\nYou can edit the data by using the following link:\n" + editURL + "\n\n\nSincerely,\nFormbot";
// Above is the column (number value is always -1) selected for activity name display.
var subjectTo = "Please update the '" +row[6] +"' activity data.";
var subjectMe = "An activity has finished today [ID: " +row[1] +"].";
MailApp.sendEmail(sendTo, subjectTo, messageTo, {name: sendername});
MailApp.sendEmail(sendMe, subjectMe, messageMe, {name: myname});
}
}
}
The problem is obviously in this part:
var form = FormApp.openById("IDremovedByMe");
var formResponses = form.getResponses();
var r = formResponses.length-1;
var editURL = formResponses[r].getEditResponseUrl();
I'm just not sure how to explain the script how to get the appropriate response.
Perhaps my approach is wrong, maybe I should tell the script to scan the form database instead the linked spreadsheet? Any ideas on how to do that?

So, I chose to insert the URLs directly into the responses sheet and reference them from there.
I used the script found here.
function injectEditURLs() {
// Form ID:
var form = FormApp.openById('IDremovedByMe');
// Name of the (main) sheet and NOT the Sheet file name where the URLs will appear:
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Responses');
var data = sheet.getDataRange().getValues();
var urlCol = 11; // The number of the column in which the URL will be inserted; A = 1, B = 2 etc.
var responses = form.getResponses();
var timestamps = [], urls = [], resultUrls = [];
for (var i = 0; i < responses.length; i++) {
timestamps.push(responses[i].getTimestamp().setMilliseconds(0));
urls.push(responses[i].getEditResponseUrl());
}
for (var j = 1; j < data.length; j++) {
resultUrls.push([data[j][0]?urls[timestamps.indexOf(data[j][0].setMilliseconds(0))]:'']);
}
sheet.getRange(2, urlCol, resultUrls.length).setValues(resultUrls);
}
Then I just referenced it (and removed the unnecessary bits) in the reminder email script with:
" + row[n] +"
So it now looks and works something like this:
function sendReminderEmail() {
var sheet = SpreadsheetApp.getActiveSheet();
var startRow = 2; // First row of data to process
var numRows = sheet.getLastRow()-1; // Number of rows to process
// Fetch the range of cells A2:B3
var dataRange = sheet.getRange(startRow, 1, numRows, sheet.getLastColumn());
// Fetch values for each row in the Range.
var data = dataRange.getValues();
//Logger.log(data)
for (i in data) {
var row = data[i];
var date = new Date();
date.setHours(0);
date.setMinutes(0);
date.setSeconds(0);
//Logger.log(date);
var sheetDate = new Date(row[13]);
//Logger.log(sheetDate);
var Sdate = Utilities.formatDate(date,'GMT+0100','yyyy:MM:dd')
var SsheetDate = Utilities.formatDate(sheetDate,'GMT+0100', 'yyyy:MM:dd')
Logger.log(Sdate+' =? '+SsheetDate)
if (Sdate == SsheetDate){
var sendTo = row[4]; // Collect email address from the fourth column (number value is always -1).
var sendMe = "xyzabcloremipsum#gmail.com"; // Enter the email address where you wish to receive a notification about a reminder sent.
var sendername = "Auto Formbot"; // Name displayed as the sender.
var myname = "Formbot"; // Name displayed as the sender to you.
var messageTo = "Based on the data you entered, the '" +row[6] +"' project with the ID: " +row[1] +" has ended.\n\nPlease mark it as 'Completed' and update the details as soon as it's convenient for you.\n\nYou can edit your data by using the following link:\n" + row[10] + "\n\nThank you for your time.\n\n\nWith kind regards,\nFormbot";
var messageMe = "The '" +row[6] +"' project with the ID: " +row[1] +" has finished today.\n\nA reminder email has been sent to " +row[4] +".\n\nYou can edit the data by using the following link:\n" + row[10] + "\n\n\nSincerely,\nFormbot";
// Above is the column (number value is always -1 because A=0) selected for activity name display.
var subjectTo = "Please update the '" +row[6] +"' activity data.";
var subjectMe = "An activity has finished today [ID: " +row[1] +"].";
MailApp.sendEmail(sendTo, subjectTo, messageTo, {name: sendername});
MailApp.sendEmail(sendMe, subjectMe, messageMe, {name: myname});
}
}
}

Your own idea about scanning from the form database is most viable option. Here is code snippet, from Google form documentation page that does exactly that :
 
// Open a form by ID and log the responses to each question.
 var form = FormApp.openById('1234567890abcdefghijklmnopqrstuvwxyz');
 var formResponses = form.getResponses();
 for (var i = 0; i < formResponses.length; i++) {
   var formResponse = formResponses[i];
   var itemResponses = formResponse.getItemResponses();
   for (var j = 0; j < itemResponses.length; j++) {
     var itemResponse = itemResponses[j];
     Logger.log('Response #%s to the question "%s" was "%s"',
         (i + 1).toString(),
         itemResponse.getItem().getTitle(),
         itemResponse.getResponse());
   }
 }
 
Here is the link to that page: https://developers.google.com/apps-script/reference/forms/item-response
Basically, you will get the form responses using form.responses() then loop through each response and get the due date and check to see the due date is same as today. Then send the edit url for that particular response.
Hope this helps, all the best

Related

Apps Script: Send email - Script sends 1 email per row instead of one email with all the info that meets the criteria

Newbie looking for some help... I can't understand what is going wrong in this script!
I am using a sheet similar to this one. My objective is to send and email to a specific address whenever certain conditions are met.
The conditions are Col R (Yesterday = 1) & Col D (Status) is different than "Resgate".
This is the output I am getting from my script. If 2 rows meet these conditions, then I get an email with the first row that meets conditions, and then another email with the first and second row that meets conditions. If there where 5 rows that meet conditions, I would receive 5 emails, and in the last one, I would have all the rows that meet conditions.
What I want to achieve is to receive only the final email with all the rows that meet conditions and avoid receiving the other ones.
Email 1
Email 2
This Is the code I am using
function SENDMAIL() {
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
// set active sheet to Sheet by name
spreadsheet.setActiveSheet(spreadsheet.getSheetByName("Sheet 1"));
var sheet = spreadsheet.getActiveSheet();
// figure out what the last row is
var lastRow = sheet.getLastRow();
var startRow = 2;
// grab all data from user to days left
var range = sheet.getRange(startRow, 1, lastRow - startRow + 1, 19);
var values = range.getValues();
var users1 = [];
var users2 = [];
var users3 = [];
var users4 = [];
var users5 = [];
var users6 = [];
// loop all data per row
values.forEach(function(row) {
if (row[17] == 1 && row[3] !== "Resgate") {
// add user if 4 or more days left
users1.push(row[3]);
users2.push(row[4]);
users3.push(row[5]);
users4.push(row[16]);
users5.push(row[15]);
users6.push(row[14]);
// if users has elements
var message = "<html><body></h1><p><b>New Requests</font2></h1>";
var names = "<ul>";
users4.forEach(function(user, i) {
names += `<p><b><li>${user} -> ${users1[i]} - ${users3[i]} - ${users2[i]} - ${users5[i]} - ${users6[i]}€ `;
});
names += "</ol>"
message = message + names + "</body></html>";
var flexmails = "Example#gmail.com";
MailApp.sendEmail(flexmails, "NEW PPR's", "", {
htmlBody: message,
noReply: true
});
} else {}
})
}
Simply move sendEmail out from the values.forEach loop and put it at the end of the script
MailApp.sendEmail(flexmails, "NEW PPR's","", { htmlBody: message, noReply: true });
values.forEach(function(row) {
if (row[17] == 1 && row[3] !== "Resgate") {
// add user if 4 or more days left
users1.push(row[3]);
users2.push(row[4]);
users3.push(row[5]);
users4.push(row[16]);
users5.push(row[15]);
users6.push(row[14]);
}
});
// if users has elements
var message = "<html><body></h1><p><b>New Requests</font2></h1>";
var names = "<ul>";
users4.forEach(function(user, i) {
names += `<p><b><li>${user} -> ${users1[i]} - ${users3[i]} - ${users2[i]} - ${users5[i]} - ${users6[i]}€ `;
});
names += "</ol>"
message = message + names + "</body></html>";
var flexmails = "Example#gmail.com";
MailApp.sendEmail(flexmails, "NEW PPR's", "", {
htmlBody: message,
noReply: true
});

Unable to add inline image to email in google apps script

I'm new to Google Apps script and am trying to add an image inline to an automated response email.
The auto reply works perfectly, the main text of the email formats well in plain text and html.
the problem i'm facing is that the image does not appear.
my code:
// This constant is written in column Y for rows for which an email
// has been sent successfully.
var EMAIL_SENT = 'EMAIL_SENT';
/**
* Sends non-duplicate emails with data from the current spreadsheet.
*/
function sendEmails2() {
var sheet = SpreadsheetApp.getActiveSpreadsheet();
SpreadsheetApp.setActiveSheet(sheet.getSheetByName('Data'))
var startRow = 2; // First row of data to process
// Fetch the range
var dataRange = sheet.getRange("L2:L1000")
var dataRange2 = sheet.getRange("K2:K1000")
var dataRange3 = sheet.getRange("O2:O1000")
var dataRange4 = sheet.getRange("Y2:Y1000")
var dataRange5 = sheet.getRange("B2:B1000")
// Fetch values for each row in the Range.
var data = dataRange.getValues();
var data2 = dataRange2.getValues();
var data3 = dataRange3.getValues();
var data4 = dataRange4.getValues();
var data5 = dataRange5.getValues();
for (var i = 0; i < data.length; ++i) {
var yesno = data2[i]
if(yesno == "Yes"){
var TFlogoUrl = "https://drive.google.com/openid=1nzmvP_zzOms1HiBoFCsVLFjDM6ZzM287";
var TFlogoBlob = UrlFetchApp
.fetch(TFlogoUrl)
.getBlob()
.setName("TFlogoBlob");
var emailAddress = data[i];
var ShipID = data3[i];
var cmdrID = data5[i];
var TFmsg = "Hi " + cmdrID + ",/n /nThank you for signing up to The Fatherhoods Lost Souls Expedition./n /nYour unique Ship ID is: " + ShipID + "/n /nWe look forward to seeing you on the expedition CMDR!/n /nFly Safe,/nThe Lost Souls Expedition team.";
var htmlTFmsg = "Hi " + cmdrID + ",<br> <br>Thank you for signing up to The Fatherhoods Lost Souls Expedition.<br> <br>Your unique Ship ID is: " + ShipID + "<br> <br>We look forward to seeing you on the expedition CMDR!<br> <br>Fly Safe,<br>The Lost Souls Expedition team.<br><img src='cid:TFlogo'>";
emailSent = data4[i]; // email sent (column Y)
if (emailSent != EMAIL_SENT) { // Prevents sending duplicates
var subject = "Lost Souls Expedition Sign up confirmation";
MailApp.sendEmail(emailAddress,subject,TFmsg,{
htmlBody: htmlTFmsg,
inlineImage:
{
TFlogo:TFlogoBlob
}
});
sheet.getRange("Y" + (startRow + i)).setValue(EMAIL_SENT);
// Make sure the cell is updated right away in case the script is interrupted
SpreadsheetApp.flush();
}
}
}
}
How about this modification?
Modification points:
You cannot retrieve the file blob from this URL var TFlogoUrl = "https://drive.google.com/openid=1nzmvP_zzOms1HiBoFCsVLFjDM6ZzM287";. If you want to retrieve the file blob from URL, please use var TFlogoUrl = "http://drive.google.com/uc?export=view&id=1nzmvP_zzOms1HiBoFCsVLFjDM6ZzM287";. 1nzmvP_zzOms1HiBoFCsVLFjDM6ZzM287 is the file ID.
As an another method, from the file ID, it is found that the values of getSharingAccess() and getSharingPermission() are ANYONE_WITH_LINK and VIEW, respectively. So you can also retrieve the blob using var TFlogoBlob = DriveApp.getFileById("1nzmvP_zzOms1HiBoFCsVLFjDM6ZzM287").getBlob().setName("TFlogoBlob");. I recommend this.
When you want to use the inline image to email, please modify from inlineImage to inlineImages.
The script which reflected above points is as follows.
Modified script:
Please modify your script as follows.
From:
var TFlogoUrl = "https://drive.google.com/openid=1nzmvP_zzOms1HiBoFCsVLFjDM6ZzM287";
var TFlogoBlob = UrlFetchApp.fetch(TFlogoUrl).getBlob().setName("TFlogoBlob");
To:
var id = "1nzmvP_zzOms1HiBoFCsVLFjDM6ZzM287";
var TFlogoBlob = DriveApp.getFileById(id).getBlob().setName("TFlogoBlob");
And
From:
inlineImage: {TFlogo:TFlogoBlob}
To:
inlineImages: {TFlogo:TFlogoBlob}
References:
sendEmail(recipient, subject, body, options)
If I misunderstand your question, please tell me. I would like to modify it.

Send email only when first two columns are filled in

I currently have this script working so that when the last row is edited it sends an email with the contents of the first two columns from that row. My issue is that if info is entered into any column of the last row then a blank email gets sent. I've tried a combination of if statements to get the result I want but either end up with the script working as it currently is, or not working at all.
// This function grabs the last row of a inventory sheet and sends the updated range to a specified recipient using a onEdit trigger
function sendEmails() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
// If edit is not made on "Iventory" sheet then function does not proceed
if (sheet.getSheetName() != "Inventory") return;
// Get last row of sheet
var lastRow = sheet.getLastRow();
// Get range of last row
var lastCell = sheet.getRange(lastRow, 1, 1, 2);
// Fetch values for each row in the Range.
var data = lastCell.getValues();
//empty string
var message =""
//Loop through each row and form CSV data
for (var i = 0; i < data.length; i++) {
var row = data[i];
message = message + row[0] + "-" +row[1] + "\n";
}
// Send one email with all the rows
var subject = "Inventory update";
MailApp.sendEmail("test#test.com", subject, message);
}
try this:
var send=true;
for (var i=0;i<data.length;i++) {
var row = data[i];
message = message + row[0] + "-" +row[1] + "\n";
if(!row[0] || !row[1]){
send=false;
break;
}
}
// Send one email with all the rows
var subject = "Inventory update";
if(send){
MailApp.sendEmail("test#test.com", subject, message);
}

Google Apps Script: How to pull values from column A based on values in column E and send all values in one email?

I'm trying to create a script for a student attendance spreadsheet that will look in Column E for the string "X". For each instance of "X", the string from column A (the student name) will be added to the body of an email. I'm pretty new to JavaScript, although I have been studying the basics. I've done a lot of research and found some scripts I was able to modify to send an individual email for each instance of X in E. However, I have not been able to figure out how to combine that information into a single email.
Here's what I have so far:
function Email_ReminderNS() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("July_August"),
EMAIL_SENT = "EMAIL_SENT",
statusArray = sheet.getDataRange().getValues();
var class = statusArray[0][8],
status = "X",
email = "XXXX"
for (i=7;i < statusArray.length;i++){
var emailSent = statusArray[i][84];
if (status == statusArray[i][4] & emailSent != EMAIL_SENT) {
var student = statusArray[i][0];
var body = "This is a No-Show Report for " +student+ " from " + class;
var subject = "No-Show Report for " + student+ " from " + class;
MailApp.sendEmail(email,subject,body,{NoReply : true});
sheet.getRange(i+1, 85).setValue(EMAIL_SENT);
SpreadsheetApp.flush();
}
}
}
I realize I'll probably need to move the sendEmail function to be outside the IF statement. I tried to create an array with the names and join those into a string and add it to the body of the email, but I've had no luck. It just ended up sending the last name instead of all of them.
If anyone has any suggestions for me I would be deeply grateful.
First set up variables to keep track of which student did not show up:
var students = [];
var student_rows = [];
Then, add student to these arrays when X is found:
if (status == statusArray[i][4] & emailSent != EMAIL_SENT) {
var student = statusArray[i][0];
students.push(student);
student_rows.push(i+1);
}
Then send the email with all student names combined (outside of the for loop like you said)
var body = "This is a No-Show Report for " + students.join(', ') + " from " + class;
var subject = "No-Show Report for " + students.join(', ') + " from " + class;
MailApp.sendEmail(email,subject,body,{NoReply : true});
Finally update the spreadsheet indicating which names were in that email:
for (var i=0; i<student_rows.length; i++) {
sheet.getRange(student_rows[i], 85).setValue(EMAIL_SENT);
SpreadsheetApp.flush();
}
Here's the complete script:
function Email_ReminderNS() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("July_August"),
EMAIL_SENT = "EMAIL_SENT",
statusArray = sheet.getDataRange().getValues();
var class = statusArray[0][8],
status = "X",
email = "francis#bposolutions.com";
var students = [];
var student_rows = [];
for (i=7;i < statusArray.length;i++){
var emailSent = statusArray[i][84];
if (status == statusArray[i][4] & emailSent != EMAIL_SENT) {
var student = statusArray[i][0];
students.push(student);
student_rows.push(i+1);
}
}
var body = "This is a No-Show Report for " + students.join(', ') + " from " + class;
var subject = "No-Show Report for " + students.join(', ') + " from " + class;
MailApp.sendEmail(email,subject,body,{NoReply : true});
for (var i=0; i<student_rows.length; i++) {
sheet.getRange(student_rows[i], 85).setValue(EMAIL_SENT);
SpreadsheetApp.flush();
}
}
There are probably many ways to implement a new version of your code, the other answer probably works but I think it can be improved (a bit).
First of all, you can get rid of the flush method that does nothing else than slowing down the function (it was originally used in the Google example to check the sent status row by row, it is useless when we send only one mail with all the data in it)
Secondly, it might be a good idea to use html format to get a better looking result.
And lastly, it is good practice to write back to the sheet using one setValues instead of multiple setValue() in a loop.
Here is a possible replacement code, you'll have to "tune" it to your needs to eventually improve the message format but the main structure is there and working.
function Email_ReminderNS() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("July_August"),
statusArray = sheet.getDataRange().getValues();
var email = Session.getActiveUser().getEmail(); //replace with the email you want, this value will send mails to you I used it for test.
var class = statusArray[0][8],
status = "X",
students = [];
for (var i=7;i < statusArray.length; i++){
var emailSent = statusArray[i][84];
if (status == statusArray[i][4] & emailSent != "EMAIL_SENT") {
students.push(statusArray[i][0]);
statusArray[i][84]="EMAIL_SENT";
}
}
var subject = "No-Show Report for " + students.length + " from " + class;
var textBody = "This is a No-Show Report for " +students.length+ " from " + class+"\n";
var HTMLBody = "<b>This is a No-Show Report for " +students.length+ " from " + class+"</b><br><br>"
+'<table style="background-color:lightblue;border-collapse:collapse;" border = 1 cellpadding = 5><th>Sent Mails</th><tr>';
for(var n in students){
HTMLBody += '<tr><td>'+n+'</td><td>'+statusArray[n][0]+'</td></tr>';
textBody += '\n'+n+' - '+statusArray[n][0];
}
HTMLBody+='</table><BR> kind regards.' ;
textBody+='\n\nKind regards';
Logger.log(HTMLBody);
Logger.log(textBody);
MailApp.sendEmail(email,subject,textBody,{'NoReply' : true, 'htmlBody' : HTMLBody});
sheet.getRange(1,1,statusArray.length,statusArray[0].length).setValues(statusArray);
}

Google App Script Grouping data in sheet to email

I have an action item Google sheet with these columns:
A - ID - a serial # 1, 2, 3, etc.
B - Assigned - date the action item was assigned
C - Product - short text name of the project or area
D - Action Item - text description of the action item
E - Owner - who is the item assigned to, this is usually just a name
like Bob L, or sometimes multiple people Bob/Ted
F - Due Date
G - Status - Pending, In process, etc.
H - Last Updated - updated by onEdit script
I - Last Edited By - updated by onEdit script
J - Owner Email - vlookup to data range to get email address(s) of
owner(s)
K - Last Reminder Sent - date of the last email sent updated by
script
I'm a total newbie with GAS so I've cobbled together snippets to get the script to send 1 email to the owner for each action item but I want to group the action items by column E (Owner) and send one email. I know I need a nested loop but I'm not sure how to proceed.
The format of the resulting email would need to be a table of columns A, B, D, F, G (at least). The current script is below:
SCRIPT
function sendEmails() {
var sheet = SpreadsheetApp.getActiveSheet();
var startRow = 3; // First row of data to process
//var numRows = 12; // Number of rows to process *CHANGE AS NEEDED*
//var numItems = getRowsData(sheet, OpenItems);
var numItems = SpreadsheetApp.getActiveSheet().getRange("OpenItems").getValues();
var numRows = numItems[0]
// Fetch the range of cells A2:B3
var dataRange = sheet.getRange(startRow, 1, numRows, 11) // must encompass Column K (11)
// Fetch values for each row in the Range.
var data = dataRange.getValues();
for (var i = 0; i < data.length; ++i) {
var row = data[i];
var actionitemid = row[0];
var assignedon = Utilities.formatDate(new Date(row[1]), "GMT-05:00", "MM/dd/yy");
var assignedto = row[4];
var project = row[2];
var actionitem = row[3];
var duedate = Utilities.formatDate(new Date(row[5]), "GMT-05:00", "MM/dd/yy");
if (duedate == "12/31/69") { // no due date
var duedate = "TBD - please update!!" ;}
var status = row[6];
var emailAddress = row[9]; // Column J = 9 (starts at A=0
var subject = "Action Item Reminder - Project: " + project;
var sheetURL = SpreadsheetApp.getActiveSpreadsheet().getUrl();
var body = "A reminder to do the following:\n\n Project: "+project + "\n Due: "+duedate+"\nAssigned: "+assignedon+"\n Owner: "+assignedto+"\n Status: " + status + "\n\nACTION ITEM: "+actionitemid+"\n=============================\n"+actionitem+"\n=============================\n\nPlease advise if you will not meet the due date ASAP.\n\nAll action items can be found in the Action Item sheet:\n"+sheetURL+".";
var emailSent = row[11]; // Column D = 3
// if (oktosend == "Y") { // Send only for marked rows
var ok = emailAddress.length
if ( emailAddress.length > 0) {
// Send email
// MailApp.sendEmail(emailAddress, subject, body);
// MailApp.sendEmail(emailAddress, "TEST", body);
MailApp.sendEmail({
to: emailAddress,
cc: "rdeloach#rentpath.com",
subject: subject,
body: body
});
// Update EmailSent
var time = new Date();
time = Utilities.formatDate(time, "GMT-05:00", "MM/dd/yy, hh:mm");
sheet.getRange(startRow + i, 11).setValue(time); // Use column for EmailSent + 1 here getRange(startRow + i, X)
// Update oktosend to N
// sheet.getRange(startRow + i, 5).setValue('N'); // Use column for oktosend + 1 here getRange(startRow + i, X)
// Make sure the cell is updated right away in case the script is interrupted
SpreadsheetApp.flush();
} //oktosend<>N
}
}
OUTPUT/RESULT
​Subject: Action Item Reminder - Project: Project X
A reminder to do the following:
Project: Project X
Due: 3/1/14
Assigned: 02/01/14
Owner: Rick D
Status: Pending
ACTION ITEM: 1
~~~~~~~~~~~~~~~~~~~~~~~
Provide the data requirements for the new database tables on project X.
~~~~~~~~~~~~~~~~~~~~~~~
Please advise if you will not meet the due date ASAP.
All action items can be found in the Action Item sheet:
END OUTPUT
Looking for help on the grouping and producing a table in Gmail.
You can put the table in the body of the message and then send it through the GmailApp service instead of MailApp.
var body = '<table><tr><td>col</td><td>val</td></tr></table>';
GmailApp.sendMail('to#example.com', 'subject', '',
{ cc: 'cc#example.com',
htmlBody: body
});