The script works from the sheet, but not as addon with the same code

246 Views Asked by At

The project is published as a Sheets add-on. A trusted tester (also a spreadsheet editor) launches an add-on and it does not work. He receives the message "You do not have access to perform that action. Please ask the owner of this item to grant access to you". If the editor starts the built-in script in the same spreadsheet with the same code, then everything works.

var ss = SpreadsheetApp.getActiveSpreadsheet();
var sName = ss.getName();
var eds = ss.getEditors();
var owner = eds[0];
var ed = eds[1];
var sheet = ss.getSheetByName("Task");
var emailAddress = owner.getEmail();
var subject = "Done! - " + sName;
var localDate = Date();
sheet.getRange(12, 2, 1, 1).setValue(localDate);
var values = sheet.getRange("B2:K11").getValues();
var message = "#" + values + "#" + localDate + "#";
MailApp.sendEmail(emailAddress, subject, message);
ss.removeEditor(ed);

Please advise where to dig.

1

There are 1 best solutions below

8
On BEST ANSWER

Installing a add-on doesn't grant all permissions to the add-on. It also needs to be enabled. Published add-ons run in AuthMode.NONE unless enabled. Try adding a menu item and running the function there first to enable it in the document.