This is where I am at:
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.
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")
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);}