0

I've a public editor addon which runs the following code to clear cell values. It is being called using google.script.run from the sidebar. It's working fine for the spreadsheets that are not shared:

Google App Script

function clearCells(){
 var spreadsheet = SpreadsheetApp.getActive();
 const spreadsheetId = spreadsheet.getId();
 const dataToClear = {ranges:['Sheet1!A1']};
 Sheets.Spreadsheets?.Values?.batchClear(dataToClear, spreadsheetId);
}

Sidebar(javascript function)

function clearCells(){
  google.script.run.clearCells();
}

The same code throws the following exception in case of shared spreadsheet.

{ [GoogleJsonResponseException: API call to sheets.spreadsheets.values.batchClear failed with error: Requested entity was not found.] name: 'GoogleJsonResponseException', details: { message: 'Requested entity was not found.', code: 404 } }

I tried to run the above code as macro on the shared spreadsheet and it worked fine (surprise).

Not sure why it fails for Editor Addon.

Edits

I am not logged into multiple accounts in the same browser, so App script is executed by a single account only. Hence the question is not duplicate.

---Issue is with the scope----

Scopes used

https://www.googleapis.com/auth/drive.file https://www.googleapis.com/auth/spreadsheets.currentonly

When I change the scopes to the following, it starts working:

https://www.googleapis.com/auth/drive.file https://www.googleapis.com/auth/spreadsheets

I am not sure why it's throwing 'Requested entity was not found' error.

Any suggestions would be appreciated.

Jayakrishnan
  • 4,232
  • 2
  • 23
  • 35
  • I was trying to test the same code by creating a new sheet and share it with some people, however this work for me every time and I was unable to reproduce the error. Are you able to reproduce it from your end in a new sheet? – Fernando Lara Feb 02 '23 at 19:37
  • @FernandoLara, is it working for the shared user?. I am calling the above code (function) using google.script.run from html page. have you done the same? – Jayakrishnan Feb 03 '23 at 05:43
  • Does the user that you shared the spreadsheet with has editor access to the sheet? – Fernando Lara Feb 09 '23 at 19:03
  • Yes, they do have. – Jayakrishnan Mar 17 '23 at 10:20

0 Answers0