Gmail Script: search then move to inbox, remove label


<strong>The goal:</strong> 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 : <a href="https://stackoverflow.com/questions/18846457/how-to-remove-gmail-label-google-apps-script" rel="nofollow">How to remove GMail label - Google Apps script</a>

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.


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

"removefromthreads" <a href="http://googlescriptreference.com/removefromthreadsthreads/" rel="nofollow">http://googlescriptreference.com/removefromthreadsthreads/</a>


  • How to get subject from gmail and put into a google doc or spreadsheet
  • How to I search using Google Drive API using Javascript?
  • NativeScript: toggleDrawerState not a function error
  • Is there any way to insert emojis into Google Apps Script?
  • TypeError: Cannot find function hasNext in object
  • How to getAs(“application/pdf”) a newly created document in Google Apps Script?
  • Using a stored integer as a cell reference
  • Extract CSV from ZIP file in gmail thread and write data to a google sheets
  • Unary operator '~' cannot be applied to an operand of type 'MyType'
  • Creating columns from results in Hive
  • Creating a subplot below a plot with an inset graph in python
  • Multiple emails selected messageMetadata.accessToken
  • Multiple lines of text in UISegmentedControl
  • Jenkinsfile - agent matching multiple labels
  • JavaFX ContextMenu how do I get the clicked Object?
  • Getting value from radiobox in Tkinter - Python
  • In Akka, is ActorContext thread safe?
  • xcode don't localize specific strings
  • Swift: Switch statement fallthrough behavior
  • Record samples being played with OpenAL
  • Google Custom Search with transparent background
  • Insert into database using onclick function
  • java.lang.NoClassDefFoundError: com.parse.Parse$Configuration$Builder on below Lollipop versions
  • What is Eclipse's Declaration View used for?
  • Spray.io: When (not) to use non-blocking route handling?
  • Can I make an Android app that runs a web view in Chrome 39?
  • Which linear programming package should I use for high numbers of constraints and “warm starts” [clo
  • Transpose CSV data with awk (pivot transformation)
  • retrieve vertices with no linked edge in arangodb
  • How to delete a row from a dynamic generate table using jquery?
  • using HTMLImports.whenReady not working in chrome
  • FormattedException instead of throw new Exception(string.Format(…)) in .NET
  • Change div Background jquery
  • Authorize attributes not working in MVC 4
  • apache spark aggregate function using min value
  • EntityFramework adding new object to nested object collection
  • costura.fody for a dll that references another dll
  • Observable and ngFor in Angular 2
  • UserPrincipal.Current returns apppool on IIS
  • java string with new operator and a literal