Home > OS >  Google Apps Script PropertiesService Permissions for AddOns
Google Apps Script PropertiesService Permissions for AddOns

Time:11-16

I'm currently developing an Editor Add-on for Google Sheets using Apps Script. There's an onOpen function that sets up the menu items.

I also have a CONFIG variable in the root (not in any function) like this:

const CONFIG = {}

function setProperties_(){
  CONFIG.tmpSheetId = PropertiesService.getScriptProperties().getProperty('TMP_SHEET_ID');
  
}

setProperties_();

If I run any functions from within the script editor, everything runs fine. No issues. However, when I do a test deployment I get the error below from the moment the onOpen() runs:

You do not have permission to call getScriptProperties

I've tried adding various script scopes from here but nothing works.

CodePudding user response:

When you first install the add-on (the entry for the add-on becomes visible in the sheet menu), it runs in AuthMode.NONE that allows you to inspect only the current user's locale. Please refer to the table here Google Add-On Authorization Lifecycle

As Cooper pointed out, calling setProperties_() in global scope occurs before your add-on is authorized by the user. Move the function call to a nested function and make sure you are through with the authorization flow first.

  • Related