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 8378101
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:50:57+00:00 2026-06-09T15:50:57+00:00

I’m trying to get the following Google Apps script to work, taken from another

  • 0

I’m trying to get the following Google Apps script to work, taken from another older Groups post. It is basically is working up to the point where the getThreads(n, m) is called. The error code coming back is:

TypeError: Cannot call method “addToThreads” of null.

Is there an easier way to debug the getThreads() function? Objective is to change the label from EVERNOTE to Scripts/Forward.

// Set up multiple labels/sub-labels and add one or more email addresses
function forwardEmails() {
  forwardThreads("EVERNOTE", "username@m.evernote.com", "@Filtered Email Archive");
//  forwardThreads("Forward/MoreItems", "username1@gmail.com, username2@gmail.com", "MORE INFO");
  }

function forwardThreads(label, addr, subjSuffix) {

  var maxSubjLength = 250; 
  var applylabel = GmailApp.getUserLabelByName("Scripts/Forward");

  // Send individual and threaded emails.
  var msgs, msg, i, j, subject, options, labels, page;
  labels = GmailApp.getUserLabelByName(label)
  var threads = labels.getThreads()
  for (i=0; i < threads.length; i++) {
    msgs = threads[i].getMessages();
    for (j=0; j < msgs.length; j++) {
      msg = msgs[j];

      subject = msg.getSubject();
      if (subject.length + subjSuffix.length > maxSubjLength) {
        subject = subject.substring(0, maxSubjLength - subjSuffix.length);
      }

      options = { htmlBody: msg.getBody(), attachments : msg.getAttachments() };

      GmailApp.sendEmail(addr, subject +" "+ subjSuffix, msg.getBody(), options);

    }
  }

  while(!page || page.length == 100) {
    page = labels.getThreads(0, 100);

  // Apply new label; move the thread out of other label
     applylabel.addToThreads(page);    // ***** Failing on this line - assume page is NULL
     labels.removeFromThreads(page);
      }  
}
  • 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-09T15:50:58+00:00Added an answer on June 9, 2026 at 3:50 pm

    The error message TypeError: Cannot call method "addToThreads" of null., in this code, means that the applylabel variable is null. It can be only if GmailApp.getUserLabelByName("Scripts/Forward"); returns null and it happens if the system can’t find the Scripts/Forward label. I assume that the user under whose identity runs the script has no such label.

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

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
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 am trying to render a haml file in a javascript response like so:
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

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.