Daralien
Daralien

Reputation: 11

TypeError: Cannot find function getSheetById in object Spreadsheet

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

Answers (2)

Chung Vũ
Chung Vũ

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

ross
ross

Reputation: 2774

Issue:

This is because function getSheetById() does not exist.


Solution:

Use openById() instead:

var s = SpreadsheetApp.openById('yourIdHere');

Reference:

Upvotes: 1

Related Questions