0

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.

Andy
  • 13
  • 5
  • 1
    Duplicate of https://stackoverflow.com/a/60552165/ – TheMaster Mar 05 '20 at 18:59
  • Does this answer your question? [Search Pattern Error since Google Scripts V8 Update](https://stackoverflow.com/questions/60551160/search-pattern-error-since-google-scripts-v8-update) – TheMaster Mar 05 '20 at 19:32
  • `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]` – TheMaster Mar 05 '20 at 19:34
  • Try this: `var vRemoveEditor = sEditors.getRange('B3:B'+nRemoveEditor).getValues().map(function(r){return r[0]});` – Cooper Mar 05 '20 at 19:52
  • @TheMaster Changing `vRemoveEditor[j]` to `vRemoveEditor[j][0]` solved my issue. If you want to post this as an answer I can mark as solved. Cheers. – Andy Mar 06 '20 at 09:43

1 Answers1

1

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]

TheMaster
  • 45,448
  • 6
  • 62
  • 85