1

I've recently used Suyash Gandhi's code from another thread in order to count the number of emails under a specific label in my Gmail account. Below is the code I used/copied.

function CountVoicemail() 
{
  var label = GmailApp.getUserLabelByName("X140");
  var labelname = label.getName();
  var mails = label.getThreads();
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Data Sheet");
  var date = new Date();
  sheet.appendRow([labelname, date, mails.length]);
}

I've set up a Trigger for this code to execute it on a daily basis at around 7- 8 PM. The code worked wonderfully for a few days and would add a new row of data every time it was triggered until the code all of a sudden stopped adding new rows at around the time it reached Row 8 in the Sheet it was modifying.

I've checked the project's trigger log and it doesn't record any errors. When I try to execute the code, it tells me the code has executed correctly despite the fact that no new data/row has been added to the Google Sheet. Is there something wrong with the appendRow statement?

tehhowch
  • 9,645
  • 4
  • 24
  • 42
  • 1
    I would delete all the blank rows at the bottom, and see if that makes any difference. You can add more blank rows back in if you want empty rows. – Alan Wells Apr 17 '19 at 21:58
  • 1
    Some troubleshooting is required. I would execute the function manually, then review the Execution transcript (View, Execution transcript), and/or add a logger statement to display the value of "labelname","date" and "mails.length". Of course, this begs the question of whether are any mail items with the "X140" label. The code must also assume that you delete or relabel those emails otherwise there would be row upon row of duplicate entries for those emails. – Tedinoz Apr 17 '19 at 23:55
  • @Tedinoz There are emails going to the label in the gmail account as I currently have a filter set up to automatically label emails with a particular subject line as "X140." I've reviewed the execution transcript and it says that everything ran fine. "Execution Succeeded." It's weird because when I log on every morning to check the spreadsheet it says that changes were made at the time I've scheduled the trigger to go off. – Jose Resendiz Apr 18 '19 at 13:21
  • 1
    @AlanWells Wells, your answer fixed the issue. For some reason the script was adding the responses all the way down to row 50,000! Thank you for your help! – Jose Resendiz Apr 18 '19 at 18:49
  • Thank you for the feedback. That confirms a suspicion about `sheet.appendRow()` that I've had. – Alan Wells Apr 18 '19 at 20:18
  • @JoseResendiz My go-to [utility](https://stackoverflow.com/a/17637159/1330560) when calculating the last row in a column. – Tedinoz Apr 18 '19 at 23:21

0 Answers0