Quantcast
Channel: Hot Weekly Questions - Web Applications Stack Exchange
Viewing all articles
Browse latest Browse all 9782

Error: TypeError: Cannot read properties of null (reading 'getThreads')

$
0
0

I'm trying to get the following to work but no matter what I do I get the same error:

ErrorTypeError: Cannot read properties of null (reading 'getThreads')

I would really like it to pull it from the emails in the Inbox but that didn't work so had to move thousands of emails to a "label"Also made sure the script is actually in the shared drive folder SOS Applicant Email Attachments.Here's the code:

function saveGmailAttachmentsToDrive() {  var label = GmailApp.getUserLabelByName("SaveToDriveAttachments");  var threads = label.getThreads();  var folder = DriveApp.getFoldersByName("SOS Applicant Email Attachments").next(); if (threads.length === 0) {    Logger.log("No emails found with the 'SaveToDrive' label."); }  for (var i = 0; i < threads.length; i++) {    var messages = threads[i].getMessages();    for (var j = 0; j < messages.length; j++) {      var attachments = messages[j].getAttachments();      for (var k = 0; k < attachments.length; k++) {        folder.createFile(attachments[k]);      }    }    threads[i].removeLabel(label); // optional, prevents re-processing  }}

Viewing all articles
Browse latest Browse all 9782

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>