Reputation: 11
function sendEmail() {
var ss = SpreadsheetApp.getActiveSheet();
var sheet1= ss.getSheets()[0];
var emailAddress = sheet1.getRange(13, 2).getValue();
var orderId = sheet1.getRange(2,4).getValue();
var dollar = 45
var message = sheet1.getRange(2,3).getValue();
var aliases = GmailApp.getAliases()
Logger.log(aliases); //returns the list of aliases you own
Logger.log(aliases[0]); //returns the alias located at position 0 of the aliases array
GmailApp.sendEmail(emailAddress,orderId, message, {'from': aliases[0]});
//MailApp.sendEmail(emailAddress, orderId, message);
}
the purpose of the code is to send people data from a spreadsheet. in line 3 I try pulling data from the sheet and it returns this error message:
TypeError: Cannot read property 'getSheets' of null
sendEmail @ Code.gs:3
Upvotes: 1
Views: 73
Reputation: 713
var ss = SpreadsheetApp.getActiveSheet();
var sheet1= ss.getSheets()[0];
Should be
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet1= ss.getSheets()[0];
OR
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet1= ss.getActiveSheet();
getActiveSpreadsheet()
selects the spreadsheet (book, document) where as getActiveSheet
gets the individual sheet within the book.
Upvotes: 1