I try to open a remote google spread sheet within a .gs.function like this:
function openOLT35A001T() {
// Datenbank-Spreadsheet
const cSSOLT = SpreadsheetApp.openById('16EBPA1TeOoMgn9fBmCJN8LwIMEGEYBSEvvxxxxxx');
// Tabelle Worksheet
const cOLT35A001T = cSSOLT.getSheetByName('OLT35A001T');
return cOLT35A001T;
}// openOLT35A001T
It works within another .gs-function without problems like this:
function lkpRecord_OLT35A001T() {
const cOLT35A001T = openOLT35A001T();
var vDataRange = cOLT35A001T.getRange("A2:E").getValues();
Logger.log("vDataRange :" + vDataRange);
}//lkpRecord_OLT35A001T
But if i call the function from within a OnEdit-Trigger I get a privilege error:
function onEdit(e) {
if(e.source.getSheetName() === "FRM35A001T" && e.range.getA1Notation() === "C5") {
lkpRecord_OLT35A001T();
}
Exception: Sie sind nicht berechtigt, SpreadsheetApp.openById anzurufen. Erforderliche Berechtigungen: https://www.googleapis.com/auth/spreadsheets
at openOLT35A001T(FRM35A001T:13:33)
at lkpRecord_OLT35A001T(FRM35A001T:45:22)
at onEdit(Code:7:3)
Why is that and how to solve?
The same behavior i get, if I put the SpreadsheetApp.openById outside a function, let's say as a global constant.