When I create an Apps Script library that accesses a spreadsheet and use it in a script then I get a permission error (for setValue in the following example).
If I call the same spreadsheet function in the script once (and then remove it) and then call the library function I will never get the permission error again (It’s reproducible).
Have you ever experienced such behavior and if yes how did you solve this problem?
Thanks
The library
function addRecord(ss, sheetName) {
var sheet = ss.getSheetByName(sheetName);
sheet.getRange("A1:A1").setValue("Hello World!");
}
The script
function myFunction() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
MyLib.addRecord(ss, "Sheet1");
}
The error message
“You don’t have the required permission to call setValue”
To close this – the issue reported by Stefan has been confirmed as an issue. We are looking into this. Permissions to a passed in spreadsheet are not being correctly absorbed by a library.
Stefan – please feel free to create a report on issue tracker if you prefer.