-1

Why can't I create this script?

function setValueTest(value) {  
  SpreadsheetApp
    .getActiveSpreadsheet()
    .getSheetByName('sheet1')
    .getRange('D20')
    .setValue('Hello');

  return(value);
}

Error message:

Error: Exception, You do not have permission to call setValue (line 11).

But if I "don't have permission", why can I run other scripts? which also define values

But if I do that I can (it doesn't):

function setValueTest(value) {
  return(value);
}
TheMaster
  • 37,620
  • 6
  • 43
  • 68
Dhenyson Jhean
  • 195
  • 2
  • 7

1 Answers1

1

I can create this function with no problem:

function setValueTest(value='five') {  
  SpreadsheetApp
    .getActiveSpreadsheet()
    .getSheetByName('sheet1')
    .getRange('D20')
    .setValue('Hello');
  Logger.log(value);
  return(value);
}

And run it:

Execution log
2:58:25 PM  Notice  Execution started
2:58:25 PM  Info    five
2:58:26 PM  Notice  Execution completed

I even ran it with this simple trigger. It will run as long as the spreadsheet it accesses is that one that it is bound to.

function onEdit(e) {
  e.source.toast('entry');
  const sh = e.range.getSheet();
  if (sh.getName() == "Sheet0" && e.range.columnStart == 1 && e.range.rowStart == 1 && e.value == "TRUE") {
    e.range.setValue(false);
    e.source.toast('Flag1');
    setValueTest();
  }
}

So I guess I can't reproduce your problem with your code.

Cooper
  • 48,630
  • 6
  • 20
  • 48