I'm trying to make a Google sheet fetch actuarial data from another sheet; the other sheet essentially acts as a look-up table. The code (with the spreadsheet id removed):
function deathProb(age,sex) {
return SpreadsheetApp.openById("<spreadsheet id>").getActiveSheet().getRange(age,sex,1,1).getValue();
};
It should be really simple, and it worked earlier this year, but about a month ago it stopped working and now when I debug it gives the error:
Cannot find method getRange((class),(class),number,number). (line 3, file "").
In the sheet itself, it gives the error "You do not have permission to perform that action (line 3)".
If I change the code to "...getRange(5,5,1,1)...", so that it doesn't use the variables "age" and "sex", then it doesn't give the error in the debugger but in the sheet itself it still gives a "You do not have permission" error. I looked around and found that triggers can cause this problem, so I added a trigger like this:
[X] deathProb From spreadsheet On edit"
and authorized the script to access the other spreadsheet, but that didn't solve either problem. Any ideas?
You are probably using this script as a custom function ? If so, this error is due to a change Google recently rolled out prohibiting the use of SpreadsheetApp.openByUrl(), SpreadsheetApp.openById(), etc.. in custom functions. You can still use this method from other contexts like a menu item, trigger, etc. Google had to roll out this change for security reasons and they won't be able to revert back to the old behavior.
The issue is listed in the issue tracker: see here.