Learn business growth with Google Analytics 4 › Forums › Google Analytics 4 › Troubleshooting email sending issues in Google Apps Script › Reply To: Troubleshooting email sending issues in Google Apps Script
-
Hey, I peeped your code and noticed in your conditional statement you write ‘if (overdueValue === “TRUE”)’. The thing is, ‘overdueValue’ is a boolean (true or false), not a string (‘TRUE’ or ‘FALSE’). So, your condition will always deliver ‘false’.
Here’s an updated version of your code using boolean instead:
`
function sendEmail() {
const ss = SpreadsheetApp.getActive();
const sh = ss.getSheetByName(“Sheet1”);
const data = sh.getRange(“B2:L80” + sh.getLastRow()).getValues();
data.forEach(r => {
let overdueValue = r[9];
if (overdueValue === true){
let name = r[10];
let message = “Reach out to ” + name;
let subject = “Reach out to this person.”;
GmailApp.sendEmail(“xxxx@gmail.com”, subject, message);
}
});
}
`
Alternatively, you can keep using string but remember to write ‘true’ in lowercase, like this:
if (overdueValue.toString() === "true")
. Remember to turn ‘overdueValue’ into a string first! Happy coding!