Bruce Wayne February 2016

Google Script Error (no permission)

This very simple ClearCell() script shown below works just fine when run from the script editor, but when called from the spreadsheet with

=IF(C1<>"",ClearCell(),)

I get YOU DO NOT HAVE PERMISSION TO CALL CLEAR CONTENT (LINE 3)

function ClearCell() {
var sheet = SpreadsheetApp.getActive().getSheetByName('Sheet1');
sheet.getRange('B1').clearContent();

}

Answers


Sandy Good February 2016

The permissions for custom functions are different than the regular Apps Script code permissions. When using the Spreadsheet service, which includes SpreadsheetApp, it is "Read Only". The clearContent() method is not "read only". It's changing data in the sheet. So even though it's not a "set" method, it's still not "Read Only".

This behavior is described in the documentation at the following link:

Google Documentation - Using Apps Script Services

You will probably need to use either a simple onEdit(e) function, or an installable "On Change" function.


Serge insas February 2016

As explained in the documentation :

A custom function cannot affect cells other than those it returns a value to. In other words, a custom function cannot edit arbitrary cells, only the cells it is called from and their adjacent cells. To edit arbitrary cells, use a custom menu to run a function instead.

you are trying to clear a cell that is not the one containing the function.

Post Status

Asked in February 2016
Viewed 3,838 times
Voted 11
Answered 2 times

Search




Leave an answer