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

Only the first thread is displayed in my Apps Scripts program, but I need all the threads

$
0
0

My issue is that the first thread in my inbox is being displayed 45 times which is the number of messages in my inbox. What I need is the for loop to go through all the threads and gather all the information in the threads into a 2D array.

I know the issue is most likely with var message = threads[i].getMessages()[0] but I'm not sure how to solve the problem.

This my code:

function TheaThreads(){    var SS =SpreadsheetApp.getActiveSpreadsheet();    var ThreadSheet = SS.getSheetByName("Threads");    var threads = GmailApp.getInboxThreads();  for (var i=0; i < threads.length; i++) {    var message = threads[i].getMessages()[0],    label = threads[i].getLabels(),    //subject = message.getSubject(),    //content = message.getPlainBody(),    ident = message.getId(),    emailfrom = message.getFrom();  if(label==null|| label== undefined|| label.length==0){    label="No Label";  }  var threadArray = new Array();  for(i=0; i<threads.length; i++){    threadArray[i] = new Array();    threadArray[i][0]= ident;    threadArray[i][1]= label;    threadArray[i][2]= emailfrom;    Logger.log(threadArray);    }   }

Viewing all articles
Browse latest Browse all 9712

Latest Images

Trending Articles



Latest Images

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