Reputation: 1
I'm trying to open a new sheet in my spreadsheet and set some values inside it, using google apps script. When calling the function, I provide one argument, which will be used to name the new sheet.
When I call the function in the sheet itself, it looks like that:
Unfortunately, I get an error saying I don't have the permissions to call the 'insertSheet()' function, although I already gave it permissions. Also, when running the same function from the script editor, it works fine, and the new sheet is being added.
I thought it might be some permissions problem, but I see no sense in that, since I already granted those permissions. The script was created through the sheet itself, so it should be bounded correctly.
Any idea of what am I missing? Please help :)
Upvotes: 0
Views: 49
Reputation: 2342
Sorry, but what you're trying to do is not possible in that way as the docs say:
Spreadsheet Read only (can use most get*() methods, but not set*()). Cannot open other spreadsheets (SpreadsheetApp.openById() or SpreadsheetApp.openByUrl()).
If your custom function throws the error message You do not have permission to call X service., the service requires user authorization and thus cannot be used in a custom function.
When you use a custom function, the spreadsheet is calling the function, therefore even if you granted permissions, those permissions were for you, not the spreadsheet. That is the problem you are having.
You could use Custom Menus in G Suite, though. That would allow you to have a menu or a button made by you in your spreadsheet, which could call a function in your Apps Script code.
Upvotes: 1