1
votes

I'm trying to get the filename of an attachment on Sheets using google apps scripts. It gives me an error : "TypeError: Cannot find function getName in object GmailAttachment,GmailAttachment" Any Ideas?? Here is my code :

function myFunction() {
 var ss = SpreadsheetApp.getActiveSheet();
 var label = GmailApp.getUserLabelByName("Label");
 var threads = label.getThreads();

for (var i=0; i<threads.length; i++)
{
  var messages = threads[i].getMessages();

  for (var j=0; j<messages.length; j++)
 {
   var msg = messages[j].getBody();
   var sub = messages[j].getSubject();
   var dat = messages[j].getDate();
   var attachment = messages[j].getAttachments().getName();

  ss.appendRow([msg, sub, dat]);
  ss.appendRow([attachment])

}
 //threads[i].removeLabel(label);
} 
}

Thanks!!

1

1 Answers

0
votes

getAttachements() method return a array of GmailAttachement. You must go throught the array to use the GmailAttachement.getName() method.