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

  • SEARCH
  • Home
  • 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 8585713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T22:08:07+00:00 2026-06-11T22:08:07+00:00

I have minimal knowledge of Javascript, but would like to use this code to

  • 0

I have minimal knowledge of Javascript, but would like to use this code to enhance my GMail experience. It works, but I also get errors. When I run the debugger in Google Spreadsheet, two functions appear to malfunction:

TypeError: Cannot call method "getThreads" of null. (line 59)

With the following Execution transcript

GmailApp.getUserLabelByName([FollowUp])

GmailApp.getUserLabelByName([FollowUp/1undefined])

Inserted comment: there is some information about the GMail API call getThreads (and others) here: https://developers.google.com/apps-script/class_gmaillabel#getThreads

What I don’t get is why it is calling Followup/1undefined -> why is it undefined? It should be Followup/1days

And another error with another function:

Cannot find method moveThreadsToInbox(. (line 26)

With nothing in the Execution transcript

The entire code is:

// Adapted from:
// http://gmailblog.blogspot.com/2011/07/gmail-snooze-with-apps-script.html
//
// To setup:
// - From the |Run| menu select |setup|
//   - if prompted to authorize, do so, and then repeat this step.
//
// - Verify the script is set to be triggered to run
//   - |Triggers| menu |Current script's triggers...|
//   - 3 triggers should exist to call e.g. 
//     - dailyUpdate, Time Driven, Daily

function getLabelName(i, labelSuffixString) {
  return "FollowUp/" + i + labelSuffixString;
}

function setup() {
  for (var i = 1; i <= 7; ++i) {
    GmailApp.createLabel(getLabelName(i, "days"));
    GmailApp.createLabel(getLabelName(i, "weeks"));
  }
  GmailApp.createLabel("FollowUp");
}

function moveToInbox(page) {
  GmailApp.moveThreadsToInbox(page);
  GmailApp.markThreadsImportant(page);
}

function cleanOldFollowUpLabels() {
  var searchString = "-label:inbox label:FollowUp";
  for (var i = 1; i <= 7; ++i) {
    searchString += " -label:" + getLabelName(i, "days");
    searchString += " -label:" + getLabelName(i, "weeks");
  }
  searchString = searchString.replace(RegExp("/", "g"), "-");
  Logger.log("cleanOldFollowUpLabels() Search String:");
  Logger.log(searchString);
  var followUpLabel = GmailApp.getUserLabelByName("FollowUp");  
  var page = null;
  // Get threads in "pages" of 100 at a time
  while(!page || page.length == 100) {
    page = GmailApp.search(searchString, 0, 100);
    Logger.log("found: " + page.length);
    if (page.length > 0)
      followUpLabel.removeFromThreads(page);   
  }
}

function update(labelSuffixString) {
  var oldLabel, newLabel, page;
  var followUpLabel = GmailApp.getUserLabelByName("FollowUp");
  for (var i = 1; i <= 7; ++i) {
    newLabel = oldLabel;
    oldLabel = GmailApp.getUserLabelByName(getLabelName(i, labelSuffixString));
    page = null;
    // Get threads in "pages" of 100 at a time
    while(!page || page.length == 100) {
      page = oldLabel.getThreads(0, 100);
      if (page.length > 0) {
        followUpLabel.addToThreads(page);
        if (newLabel) {
          // Move the threads into "today’s" label
          newLabel.addToThreads(page);
        } else {
          moveToInbox(page);
        }     
        // Move the threads out of "yesterday’s" label
        oldLabel.removeFromThreads(page);
      }  
    }
  }
}

function dailyUpdate() {
  update("days");
}
function weeklyUpdate() {
  update("weeks");
}

Also here: http://pastie.org/4790086.js

  • 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-11T22:08:08+00:00Added an answer on June 11, 2026 at 10:08 pm

    mm.. with the help of a colleague, we found the answer to my own problem. I had three triggers running: A daily trigger, a weekly trigger, and the update trigger. Now the update trigger was not necessary, because it was called upon by the daily and weekly trigger, and without any input. That caused the error. Now I have to wait and see if there are any errors and if the script works.

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

Sidebar

Related Questions

This is a minimal test case of some code that I actually have. It
I'll preface this by saying I have minimal experience with both Perl and Socket
Sorry if you feel like this has been asked but I have read the
I have some knowledge in C/C++ but only using the Console. I'd like to
I may be assigned an Android project, and have minimal experience with Java but
Let me begin by saying my Oracle knowledge is minimal. We have a proprietary
I have a perl array of to-do tasks that looks like this: @todos =
I'm new to ExtJS and only have minimal javascript skills in general. I'm going
I'm learning CL, and I have minimal experience in other languages. Could someone explain
I have an SVN server, and I'd like to use our LDAP server for

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.