Email PDF Help

25 views
Skip to first unread message

Jeff W

unread,
Jan 25, 2023, 5:39:19 PMJan 25
to Google Apps Script Community
I'm trying to make the script pull an email address from the "Invoices" sheet at A1. What am I doing wrong here?

function sendReport() {
  SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Data").hideSheet();
  SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Lists").hideSheet();
  var message = {
    to: SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Invoice').getRange(1,1),
    subject: "Chroma Invoice",
    body: "Please see your attached invoice!",
    name: "Bob",
    attachments: [SpreadsheetApp.getActiveSpreadsheet().getAs(MimeType.PDF).setName("Chroma Invoice")]
  }
  MailApp.sendEmail(message);
  SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Data").activate();
  SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Lists").activate();

Bradley Jordan

unread,
Jan 30, 2023, 6:52:47 AMJan 30
to Google Apps Script Community
Hi Jeff,

Apologies if you already fixed this, but it looks like in your message, the to: field is just getting a range rather than the value in that range, so you need to put:
 to: SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Invoice').getRange(1,1).getValue(),

(I think!)
Reply all
Reply to author
Forward
0 new messages