0
votes

If anyone can offer advice about why this function isn't working, I would appreciate it. It's basically copied right out of the Google API reference: https://developers.google.com/apps-script/class_pageprotection#getUsers

function getUsers() {
  var sheet = SpreadsheetApp.getActiveSheet();
  var permissions = sheet.getSheetProtection();
  var users = permissions.getUsers();

  Browser.msgBox(users);
}

When I run the script, I get an empty box with the title "Apps Script" and no list of users.

Any help would be greatly appreciated. Thanks!

Jessica

1
Might be obvious, but have you logged into the api?Rivasa
Not obvious to me, sorry (big noob here). I'm not sure... My other function in the same script file is working just fine. How is logging in to the API different from logging in to my account?prairieskygal
You need to usually have an API key and access it at the beginning of the script.Rivasa

1 Answers

1
votes

That function only returns values when sheet protection is enabled (by selecting Tools - Protect Sheet).

When the sheet is protected, the function will return the list of users you granted access to and the code will work as expected.