0

I am trying to automate a google spreadsheet on google script editor. However, when I try to identify the spreadsheet and select as the one that we are working on, it is written in the documentation cited below (openById) that scripts that use this method require authorization with one or more of the following scopes: --> https://www.googleapis.com/auth/spreadsheets.currentonly --> https://www.googleapis.com/auth/spreadsheets

When I add these scopes, my function doesn't run. It only runs when those scopes are not added. Either way, I am met with the error msg that reads: "We are sorry, a server error occurred. Please wait a bit and try again."

https://developers.google.com/apps-script/reference/spreadsheet/spreadsheet-app#openbyidid

I tried various methods include OpenByUrl and getActiveSpreadsheet...

function automatedInvoiceEmailing() {
  var people = [];

  // selecting the spreadsheet (without the bottom line, the function works just fine)
  var ss = SpreadsheetApp.openById("1jdn3S1Iv2zDAqF6Hyy3fybKARZJYmg-LJVdUWJJS3LA");
}

Either way, I am met with the error msg that reads: "We are sorry, a server error occurred. Please wait a bit and try again."

I expected the sheet to have been selected

Edit: hmm, when I copied the google sheets and saved the new code, it runs properly!! :)

  • Is your script bound to your spreadsheet i.e. do you access it via `Tools > Script Editor` or is it a standalone file? – ross Jun 27 '19 at 08:18
  • Yes, I accessed it via the ```Tools > Script Editor``` function in the spreadsheet @ross – Sabrina Chow Jun 27 '19 at 09:51

1 Answers1

0

Since you are working with a bounded script (bound to the sheet you’re working with), the way to get a reference to the sheet is with var ss = SpreadsheetApp.getActiveSheet();, this will provide a reference to the bound document. You would use openById() to access another file.

As for scopes, they are added automatically when you run the script for the first time, it will ask for your permission to access your data, and when you accept, google adds them to the script project automatically.

Here are some quick-start examples on working with sheets and apps script

AMolina
  • 1,355
  • 1
  • 7
  • 17
  • that was what I did initially but it did not work out and I got the same server error – Sabrina Chow Jun 28 '19 at 01:39
  • @SabrinaChow Did you enable Spreadsheet Advanced Services?. Also, according to your update to the question, is it working now? – AMolina Jun 28 '19 at 07:51