Andy
Andy

Reputation: 13

Script - Add/Remove Google Sheet Editors for a list

Example Document: Link

I have had a working script that would add or remove editors from a specified sheet ID for a good few months until recently it has started giving an error of:

Exception: The parameters (number[]) don't match the method signature for SpreadsheetApp.Spreadsheet.removeEditor.

Nothing has changed recently regarding the input I am providing the script so I am at a bit of a loss.

The script is as follows:

  function runEmailAccess(){
  
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sEditors = ss.getSheetByName('Editors');
  var sheet = SpreadsheetApp.openById("SHEETID");
  
  var nAddEditor = sEditors.getRange('A2').getValue();
  if (nAddEditor != 0){
  var vAddEditor = sEditors.getRange('A3:A'+nAddEditor).getValues();
  sheet.addEditors(vAddEditor);
   }
  
  var nRemoveEditor = sEditors.getRange('B2').getValue();
  if (nRemoveEditor != 0){
  var vRemoveEditor = sEditors.getRange('B3:B'+nRemoveEditor).getValues();
  
  for (j=0;j<vRemoveEditor.length;j++) {
    sheet.removeEditor(vRemoveEditor[j])
  }
  }
  
}

The script takes the row number of last email in the list from Row 2 then takes the emails for row 3 to that row via .getRange.

enter image description here

Any help regarding this would be of great help. Thanks.

Upvotes: 0

Views: 421

Answers (1)

TheMaster
TheMaster

Reputation: 50462

vRemoveEditor is 2D array. You're indexing only into the outer array with vRemoveEditor[j]. You need to index into both to get primitive values: vRemoveEditor[j][0]

Upvotes: 1

Related Questions