Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7938911
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T22:56:22+00:00 2026-06-03T22:56:22+00:00

I’m getting the following error: TypeError: Cannot read property 0.0 from null. (line227) I’ve

  • 0

I’m getting the following error:
“TypeError: Cannot read property “0.0” from null. (line227)”

I’ve been looking through the documentation here: https://developers.google.com/apps-script/articles/gmail-stats#section1
But haven’t been able to troubleshoot.

Line227:
variables.dayOfEmailsReceived[day]++;

Sorry, new to stackoverflow but any help greatly appreciated.

Reference:

var BATCH_SIZE = 50;
var ss = SpreadsheetApp.getActiveSpreadsheet();
// If you are using several email addresses, list them in the following variable 
// - eg 'romain.vialard@gmail.com,romain.vialard@example.com'
var aliases =  'romain.vialard@euromed-management.com';

function activityReport() {
var status = ScriptProperties.getProperty("status");
if (status == null) {
    // If the script is triggered for the first time, init
    init_();
}
else {
    status = Utilities.jsonParse(status);
    var previousMonth = new Date(new Date().getFullYear(), new Date().getMonth() - 1, 1).getMonth();
    if (status == null || (status.customReport == false && status.previousMonth != previousMonth)) {
        init_();
        fetchEmails_(status.customReport);
    }
    // If report not sent, continue to work on the report
    else if (status.reportSent == "no") {
        fetchEmails_(status.customReport);
    }
}
}

function fetchEmails_(customReport) {
var variables = Utilities.jsonParse(ScriptProperties.getProperty("variables"));
if (!customReport) {
    var query = "after:" + variables.year + "/" + (variables.previousMonth) + "/31";
    query += " before:" + new Date().getYear() + "/" + (variables.previousMonth + 1) + "/31";
}
else {
    var query = "after:" + Utilities.formatDate(new Date(variables.startDate), variables.userTimeZone, 'yyyy/MM/dd');
    query += " before:" + Utilities.formatDate(new Date(variables.endDate), variables.userTimeZone, 'yyyy/MM/dd');
}
query += " in:anywhere -label:sms -label:call-log -label:chats -label:spam -filename:ics";
query += " -from:maestro.bounces.google.com -from:unified-notifications.bounces.google.com -from:docs.google.com";
query += " -from:group.calendar.google.com -from:apps-scripts-notifications@google.com";
query += " -from:sites.bounces.google.com -from:noreply -from:notify -from:notification";
var startDate = new Date(variables.startDate).getTime();
var endDate = new Date(variables.endDate).getTime();
var conversations = GmailApp.search(query, variables.range, BATCH_SIZE);
variables.nbrOfConversations += conversations.length;
var sheets = ss.getSheets();
var people = sheets[0].getDataRange().getValues();
var record = [];
for (var i = 0; i < conversations.length; i++) {
    Utilities.sleep(1000);
    var conversationId = conversations[i].getId();
    var firstMessageSubject = conversations[i].getFirstMessageSubject();
    var starred = false;
    if (conversations[i].hasStarredMessages()) {
        variables.nbrOfConversationsStarred++;
        starred = true;
    }
    var important = false;
    if (conversations[i].isImportant()) {
        variables.nbrOfConversationsMarkedAsImportant++;
        important = true;
    }
    var location = "";
    var labels = conversations[i].getLabels();
    var nbrOfLabels = labels.length;
    if (nbrOfLabels == 0) {
        if (conversations[i].isInInbox()) {
            variables.nbrOfConversationsInInbox++;
            location += "Inbox,";
        }
        else if (conversations[i].isInTrash()) {
            variables.nbrOfConversationsInTrash++;
            location += "Trashed,";
        }
        else {
            variables.nbrOfConversationsArchived++;
            location = "Archived";
        }
    }
    else {
        variables.nbrOfConversationsInLabels++;
        for (var j = 0; j < nbrOfLabels; j++) {
            location += labels[j].getName() + ",";
        }
    }
    var youReplied = false;
    var youStartedTheConversation = false;
    var someoneAnswered = false;
    var messages = conversations[i].getMessages();
    var nbrOfMessages = messages.length;
    variables.nbrOfEmailsPerConversation[nbrOfMessages]++;
    for (var j = 0; j < 10; j++) {
        if (variables.topThreads[j][1] < nbrOfMessages) {
            variables.topThreads.splice(j, 0, [firstMessageSubject, nbrOfMessages]);
            variables.topThreads.pop();
            j = 10;
        }
    }
    var timeOfFirstMessage = 0;
    var waitingTime = 0;
    for (var j = 0; j < nbrOfMessages; j++) {
        var process = true;
        var date = messages[j].getDate();
        var month = date.getMonth();
        if (customReport) {
            if (date.getTime() < startDate || date.getTime() > endDate) {
                process = false;
            }
        }
        else {
            if (month != variables.previousMonth) {
                process = false;
            }
        }
        if (process) {
            //////////////////////////////////
            // Fetch sender of each emails
            //////////////////////////////////
            var from = messages[j].getFrom().replace(/"[^"]*"/g,'');
            if (from.match(/</) != null) {
                from = from.match(/<([^>]*)/)[1];
            }
            var time = Utilities.formatDate(date, variables.userTimeZone, "H");
            var day = Utilities.formatDate(date, variables.userTimeZone, "d") - 1;

            // Use function from Utilities file
            variables = countSendsPerDaysOfWeek_(variables, date, from);
            var body = messages[j].getBody();
            // Use function from Utilities file
            var resultsFromCalcMessagesLength = calcMessagesLength_(variables, body, from);
            variables = resultsFromCalcMessagesLength[0];
            var messageLength = resultsFromCalcMessagesLength[1];
            var cc = messages[j].getCc().replace(/"[^"]*"/g,'').split(/,/);
            for (var k = 0; k < cc.length; k++) {
                if (cc[k].match(/</) != null) {
                    cc[k] = cc[k].match(/<([^>]*)/)[1];
                }
            }
            var reg = new RegExp(from, 'i');
            if ((variables.user + aliases).search(reg) != -1) {
                if (j == 0) {
                    youStartedTheConversation = true;
                    timeOfFirstMessage = date.getTime();
                }
                if (j > 0 && !youStartedTheConversation) {
                    if (!youReplied) {
                        youReplied = true;
                        // Use function from Utilities file
                        variables = calcWaitingTime_(variables, date, timeOfFirstMessage, youStartedTheConversation);
                    }
                }
                variables.nbrOfEmailsSent++;
                variables.timeOfEmailsSent[time]++;
                variables.dayOfEmailsSent[day]++;
                if (customReport) {
                    variables.monthOfEmailsSent[month]++;
                }
                var sharedWithTheOutsideWorld = false;
                var to = messages[j].getTo().replace(/"[^"]*"/g,'').split(/,/);
                for (var k = 0; k < to.length; k++) {
                    if (to[k].match(/</) != null) {
                        to[k] = to[k].match(/<([^>]*)/)[1];
                    }
                    if (to[k].search(variables.companyname) == -1){
                      sharedWithTheOutsideWorld = true;
                    }
                    var found = false;
                    for (var l = 0; l < people.length; l++) {
                        if (to[k] == people[l][0]) {
                            people[l][2]++;
                            found = true;
                        }
                    }
                    if (!found) {
                        people.push([to[k], 0, 1]);
                    }
                }
                if(!sharedWithTheOutsideWorld){
                  variables.sharedInternally++;
                }
            }
            else {
                if (j == 0) {
                    timeOfFirstMessage = date.getTime();
                }
                else if (youStartedTheConversation && !someoneAnswered) {
                    someoneAnswered = true;
                    // Use function from Utilities file
                    variables = calcWaitingTime_(variables, date, timeOfFirstMessage, youStartedTheConversation);
                }
                var found = false;
                for (var k = 0; k < people.length; k++) {
                    if (from == people[k][0]) {
                        people[k][1]++;
                        found = true;
                    }
                }
                if (!found) {
                    people.push([from, 1, 0]);
                }
                var to = messages[j].getTo().replace(/"[^"]*"/g,'');
                var checkSendToYou = false;
                var aliasesTemp = new Array(variables.user).concat(aliases.split(','));
                for(var k = 0; k < aliasesTemp.length; k++){
                    if(aliasesTemp[k] != ''){
                        var reg = new RegExp(aliasesTemp[k], 'i');
                        if (to.search(reg) != -1) {
                            checkSendToYou = true;
                        }
                    }
                }
                if(checkSendToYou)variables.sentDirectlyToYou++;
                var sharedWithTheOutsideWorld = false;
                to = to.split(/,/);
                for (var k = 0; k < to.length; k++) {
                    if (to[k].match(/</) != null) {
                        to[k] = to[k].match(/<([^>]*)/)[1];
                    }
                    if (to[k].search(variables.companyname) == -1){
                      sharedWithTheOutsideWorld = true;
                    }
                }
                if(sharedWithTheOutsideWorld == false && from.search(variables.companyname) != -1){
                  variables.sharedInternally++;
                }
                variables.nbrOfEmailsReceived++;
                variables.timeOfEmailsReceived[time]++;
                variables.dayOfEmailsReceived[day]++;
                if (customReport) {
                    variables.monthOfEmailsReceived[month]++;
                }
            }
            if (to != null) {
                to = to.toString();
            }
            if (cc != null) {
                cc = cc.toString();
            }
            var dayOfWeek = Utilities.formatDate(date, variables.userTimeZone, "EEEE");
            record.push([date, dayOfWeek, firstMessageSubject, from, to, cc, messageLength, location]);
        }
    }
    if (youStartedTheConversation) {
        variables.nbrOfConversationsStartedByYou++;
    }
    if (youReplied) {
        variables.nbrOfConversationsYouveRepliedTo++;
    }
}
variables.range += BATCH_SIZE;
ScriptProperties.setProperty("variables", Utilities.jsonStringify(variables));
sheets[0].getRange(1, 1, people.length, 3).setValues(people);
if (record[0] != undefined && sheets[1].getMaxRows() < 38000) {
    sheets[1].getRange(sheets[1].getLastRow() + 1, 1, record.length, record[0].length).setValues(record);
}
if (conversations.length < BATCH_SIZE) {
    sendReport_(variables);
}
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T22:56:24+00:00Added an answer on June 3, 2026 at 10:56 pm

    The error indicates that and day is 0 variables.dayOfEmailsReceived is null. It’s not possible to refer to an index of null. variables.dayOfEmailsReceived is created in the init_() function, so check that you have that function defined and are using it correctly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.