I am using IMPORTFEED to push CNN news feed into Google Sheets. When an article matches todays date, it sends an email. Perfect.
However, I need to do this on multiple rows rather than just one. Which will involve some "for loops" perhaps which I am unsure about.
Here is the Google App Script
function sendEmails() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet1"); // To only handle the "IMPORT & LOGIC" sheet
// Get values from formulas in Row 2
var rsstitle = sheet.getRange('A4')
var rsslink = sheet.getRange('B4')
var rssdate = sheet.getRange('C4')
var feeddesc = sheet.getRange('D4')
var convdate = sheet.getRange('E4')
var todaysdate = sheet.getRange('F2') // STATIC CELL
var myemail = sheet.getRange('G2') // STATIC CELL
// Pull formula values from Row 2
var title = rsstitle.getValue();
var link = rsslink.getValue();
var rsdate = rssdate.getValue();
var desc = feeddesc.getValue();
var feeddate = convdate.getValue();
var today = todaysdate.getValue();
var emailcell = myemail.getValue();
var sourceRange = sheet.getRange("A2:E21");
var sourceData = sourceRange.getValues();
for (row in sourceData) {
// If todays date and feed date do not match, go to next row
if (feeddate.valueOf() != today.valueOf()) { // A bit tricky matching dates using the above but this seems to work
return;
}
var emailAddress = emailcell;
// Produce and output email title such as "Example page has chaged"
var subject = title;
var message = desc;
MailApp.sendEmail(emailAddress, subject, message);
}
}
The Google Sheet is here and can be copied using "Make a copy" https://docs.google.com/spreadsheets/d/1TF2zdA3DKnFd9YjRbfpyB6GnJwvFr1bhNKLVrd23zpc/edit?usp=sharing
So ideally, based on that feed with a App Script that loops. I should get 2 emails from that list of news stories. Rather than one.