Search code examples
google-apps-scriptgmail

Gmail Script: search then move to inbox, remove label


The goal: Make Label1 labelled emails return to the inbox, and remove Label2 from that email.

This is what I have so far:

function _forceInbox() {
 var label = GmailApp.getUserLabelByName("Label1");
  var threads = GmailApp.search('label: LABEL2 is:starred OR label:Not-Done');
   for (var i = 0; i < threads.length; i++) {
    label.removeFromThread(threads[i]);
      threads[i].moveToInbox();
  }
}

I got this using : How to remove GMail label - Google Apps script

I get this error: TypeError: Cannot call method "removeFromThread" of null. (line 8, file "myfile") What does this mean?

Thanks so much for your help.


Solution

  • The answer was to add an 's' I wish I had known before all this hassle.

    "removefromthreads" http://googlescriptreference.com/removefromthreadsthreads/