Reputation: 11
I want to have an automatic email machine, without having to write all of the messages and email addresses myself.
I'm really new to this, so please don't be too harsh.
function sendOrder() {
var ui = SpreadsheetApp.getUi();
var response = ui.alert('Are you sure you want to send the order?',
ui.ButtonSet.YES_NO);
var deliveryDate = ui.prompt('Delivery date:');
// Process the user's response.
if (response == ui.Button.YES) {
var s = SpreadsheetApp.getActive().getSheetById('1pON34oXVhlpC8goyBxfu6-Gw92tgQBUVUpskZUtgp4E');
var ss = SpreadsheetApp.getActiveSpreadsheet();
var range = ss.getActiveSheet().getDataRange();
var range = s.getRange('A1:C102');
var to = "[email protected]";
var body = '';
var htmlTable = SheetConverter.convertRange2html(range);
var body = "Here is the table:<br/><br/>" +
htmlTable +
"<br/><br/>The end."
MailApp.sendEmail(to, 'Subject', body, {
htmlBody: body
});
};
SpreadsheetApp.getUi().alert('Yeah! Your order has been sent :)');
}
I just expect this to give me a box to enter a date, once the date is entered it should say it has sent and our supplier will see all of the orders.
Upvotes: 1
Views: 1487
Reputation: 1
you need to add the function getSheetById(id):
function getSheetById(id) {
return SpreadsheetApp.getActive().getSheets().filter(
function(s) {return s.getSheetId() === id;}
)[0];
}
Upvotes: 0
Reputation: 2774
This is because function getSheetById()
does not exist.
Use openById()
instead:
var s = SpreadsheetApp.openById('yourIdHere');
Upvotes: 1