1

I am new to google sheets and scripts. I have created a searchable product list in google sheet and created a button clear the contents(not the formulas). Everything will work fine when I logged in. If i share the link with someone the script is not working and showing an error. The sheet is perfectly working.

function myFunction() {

    var sheet = SpreadsheetApp.getActiveSheet();
    var rangeList = sheet.getRangeList(['A8', 'E24']);
    rangeList.clear({contentsOnly: true});

}

Is there any way to resolve this, please?

player0
  • 124,011
  • 12
  • 67
  • 124
sanu paul
  • 21
  • 2
  • Could you please share what error are you getting to see? Would also help if you could perhaps create a copy of the sheet and share it with us (SO community) with dummy content. – Sourabh Choraria Oct 26 '19 at 12:46
  • https://docs.google.com/spreadsheets/d/1g3LdHE1UqbHClIDNCvvthAX5xatyvvePvwyigxKa2a0/edit?usp=sharing – sanu paul Oct 26 '19 at 13:37
  • please see the above link – sanu paul Oct 26 '19 at 13:37
  • So, when I clicked the **Clear** button, it asked me for to authorise for the 1st time and cleared all the cells, as required. Sorry, but I didn't experience any error in the sheet. – Sourabh Choraria Oct 26 '19 at 14:49
  • I'm confused you say you received an error in your question but in your comment you say you didn't receive an error. If you received an error an would like some help then perhaps you could share the error with us or possibly withdraw the question. – Cooper Oct 26 '19 at 15:12
  • 1
    "Script myFunction experienced an error Details Dismiss" .. This is the error message that I am getting. If I signed into my google account and execute the script, the script will run, but on the shared link, getting the above error message. – sanu paul Oct 27 '19 at 09:53
  • @SourabhChoraria, I am not getting to authorise the script as a different user/not logged into any Google account. Could you please try by not logging into your google account. – sanu paul Oct 27 '19 at 09:55
  • 1
    Possible duplicate of [Container-Bound Google Script not executing even after the container has been shared](https://stackoverflow.com/questions/18282208/container-bound-google-script-not-executing-even-after-the-container-has-been-sh) – Tedinoz Oct 27 '19 at 11:32

1 Answers1

1

What you want to achieve is sadly not possible :( Please refer to Authorization for Google Services.

In line one of the documentation, you'll find -

Apps Script requires user authorization to access private data from built-in Google services or advanced Google services.

Given that you're using SpreadsheetApp service to access Sheets, a user needs to be logged in for the script functions to do as required.

Hope this clarifies.

Sourabh Choraria
  • 2,255
  • 25
  • 64