1

This is where I am at:

  1. I have a Spreadsheet where Column A contains some data in plain text. The text in Column A is automatically updated once a day in the morning.

  2. In Column B I have a formula that looks for a certain words in Column A. If it finds a match then YES appears in the corresponding cell. This is what the formula in Column B basically looks like =IF(ISNUMBER(SEARCH("John Doe",A1)), "YES")

  3. I have a script which looks at Column B and if a cell is populated by the above formula to say YES it sends an email to me. The problem is, it only works when the column is populate with plain text values and does not work if it is populated via a formula.

Is there anyway to change the script I am using so it works despite the cell being populate via a formula?

Here is the script I am using:

function sendEmail(e) {
var thisSheet = e.source.getActiveSheet();
if (thisSheet.getName() !== 'Sheet1' || e.range.columnStart !== 1 || e.range.rowStart == 1 || e.value !== 'YES') return;
var body, headers = thisSheet.getRange(1, 1, 1, 14)
    .getValues()[0],
    thisRow = thisSheet.getRange(e.range.rowStart, 1, 1, 14)
    .getValues()[0],
    recipients = "email@gmail.com",
    subject = "YES " + e.source.getName(),
    body = "",
    i = 0;
while (i < 14) {
    body += headers[i] + ':\t' + thisRow[i] + '\n';
    i++;
}
body += "\n\nVisit " + e.source.getUrl() + " to view the changes."
MailApp.sendEmail(recipients, subject, body);}
user3745883
  • 93
  • 1
  • 10
  • You could scan the range periodically with a time based trigger rather than an onEdit (which I assume you are using). – Robin Gertenbach Apr 06 '17 at 08:28
  • You may want to add [Installable Triggers](https://developers.google.com/apps-script/guides/triggers/installable) which will let your script run a function automatically when a certain [event](https://developers.google.com/apps-script/guides/triggers/events#edit) occurs such as `onEdit(e)`. This related [SO post](http://stackoverflow.com/questions/15336907/email-notification-if-cell-is-changed) might also help. – Teyam Apr 06 '17 at 11:12
  • I changed the trigger from an onEdit to run every 5 minutes but now I do not get any emails. – user3745883 Apr 06 '17 at 13:24
  • From further research I do not believe the sendEmail function can work when set to a time based trigger. I need to find another work around. – user3745883 Apr 06 '17 at 13:51

0 Answers0