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
-
The issue could reside in a couple of potential areas in your code.
One problem could be in how you determine the data range in your Google Sheets. The code “B2: L80” + sh.getLastRow() is meant to get data from B2 to the last row of the L column. However, it may not be working as you expect because “B2: L80” + sh.getLastRow() translates to “B2: L80[Ending Row Number]”, which is not a valid range in Google Sheets. Instead, you’d want it to translate to “B2:L[Ending Row Number]”.
Another potential issue could be with the comparison operator. You are checking if overdueValue is a string “TRUE”, instead of a Boolean true. Depending on how your sheet is set up, this could be the cause of the problem. If the overdueValue is recorded as a Boolean value in your sheet (i.e., true without quotes), then your if condition will never be truthy.
Lastly, ensure that you are using the correct column index. The r[9] notation is zero-based, r[0] represents the ‘B’ column, therefore r[9] represents the ‘K’ column and not ‘J’ column. Ensure that the overdueValue represents the correct column on your sheet. Similarly, check the name variable, r[10] represents the ‘L’ column.
Also, make sure the email value “xxxx@gmail.com” is replaced with the actual email address you want the function to send notifications to.
You should also check if the function has the necessary permissions to access the GmailApp, and that any script triggers that are supposed to call this function are set up correctly.