When Apps Script displays No permission to call service, When you invoke an Apps Script function directly from a spreadsheet cell formula (like =GETDATA(A1)), it runs in Google Sheets sandboxed custom-function mode, which prohibits calling services that require user authorization (SpreadsheetApp.openById, DriveApp, GmailApp, CalendarApp, PropertiesService write, or setValue).
Step-by-Step Resolution
- Move any side-effecting logic (writing to other cells via setValue, opening external files via openById, or sending emails) out of cell formulas and into a Custom Menu item created inside onOpen() or a button drawing.
- Use only permitted read-only/anonymous services inside custom functions: pure JavaScript math/strings, CacheService, Utilities, LanguageApp, or public UrlFetchApp endpoints.
- Pass all cell ranges directly as arguments inside the formula (e.g., =CLEANDATA(A2:D100)) so the custom function returns a 2D array instead of calling getActiveSpreadsheet().getRange().
Common Edge Cases
Users often test a script in the Apps Script editor where it succeeds (because editor runs use full user OAuth tokens), then paste =myFunc() into a cell and hit immediate permission errors.
When This Doesn't Work
If external spreadsheets must be pulled dynamically via a formula without scripting privileges, use native =IMPORTRANGE() instead of writing an openById custom function.
Prevention Tips
Design in-cell custom functions as pure data transformers taking 2D range inputs and returning 2D array outputs, reserving mutating Workspace API calls for menu actions or triggers.
Relevant Tools & Guides
- JSON Formatter & Validator — Format, beautify, inspect syntax errors, and minify JSON payloads.
- Regex Tester & Debugger — Test regular expressions against target text with live match highlighting and flags.
- Read Google Apps Script Automation Guide: Connect Workspace Services with Code →
- Read Google Sheets Formulas Every Business User Should Know in 2026 →
Related Errors
Frequently Asked Questions
Why does setValue() fail inside a Google Sheets custom function?
Custom functions must return values into their own formula cell (or spill array) and cannot modify arbitrary cells elsewhere in the spreadsheet.
Can custom functions call external public APIs with UrlFetchApp?
Only limited anonymous requests are permitted, and even then Google recommends using menu-triggered scripts or add-ons for authenticated API calls.
Does publishing as a Workspace Add-on remove custom function restrictions?
No. Even published add-on custom functions adhere to the exact same custom-function service sandbox restrictions.
What is the alternative to calling openById inside a cell?
Add an onOpen menu item ("Refresh Data") that runs an authorized function on click and writes values straight into the sheet.