Search code examples
google-apps-scriptproxyproxy-object

only one user encounters this type error: selection.getCurrentCell is not a function


This code is being used for some years now, without any problem. The code is triggered by clicking a small image in the spreadsheet. Since a few days one of the users encounters this "type error: selection.getCurrentCell is not a function". For other users all works as before. Seems to me this is not a programming problem but rather an authorization problem or something? The user who encounters problems does NOT use a device managed by the company, the others DO. Any suggestions?

/** @OnlyCurrentDoc */
function Voeg1RijToe() {
  var date = new Date();
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var s = ss.getSheetByName('Schakel');
  var r = s.getRange('B:B');
  var v = r.getValues();
  for(var i=v.length-1;i>=0;i--)
    if(v[0,i]=='blanco'){
var range = s.getRange('A1');
range.activate();
var selection = s.getSelection();
// Current cell: A1
var currentCell = selection.getCurrentCell();
      /* ---- Zoek in de kolom B:B naar blanco ------ */
      /* ---- Voeg 1 rij erONDER toe en vul de datum van vandaag in ------ */
      s.getCurrentCell().offset(i,1).activate();
      s.insertRowsAfter(s.getActiveRange().getRow(), 1);
      /* --hieronder was offset(0,0,1)-- */
      s.getActiveRange().offset(1, 0, 1, s.getActiveRange().getNumColumns()).activate();
      s.getCurrentCell().offset(0, -1).activate();
      s.getCurrentCell().setValue(date);
      s.getCurrentCell().activate();
     /* ------Ga 1 rij naar boven en selecteer cellen met formules en copieer in de nieuwe rij ---------- */
       s.getCurrentCell().offset(-1, 2, 1, 3).activate();
  var destinationRange = s.getActiveRange().offset(0, 0, 2);
  s.getActiveRange().autoFill(destinationRange, SpreadsheetApp.AutoFillSeries.DEFAULT_SERIES);
  s.getCurrentCell().offset(0, 5).activate();
  destinationRange = s.getActiveRange().offset(0, 0, 2);
  s.getActiveRange().autoFill(destinationRange, SpreadsheetApp.AutoFillSeries.DEFAULT_SERIES);
  s.getCurrentCell().offset(0, 7, 1, 3).activate();
  destinationRange = s.getActiveRange().offset(0, 0, 2);
  s.getActiveRange().autoFill(destinationRange, SpreadsheetApp.AutoFillSeries.DEFAULT_SERIES);
  s.getCurrentCell().offset(1, -14, 1, 1).activate(); 
      /* offset(rowOffset, columnOffset, numRows, numColumns) */
     /* ---------------- */ 
      /* s.getCurrentCell().activate(); */
    };
};

/* Kris Paeschuyzen: juni 2019 */

On the chromebook device of the user, I deleted cookies and browsing history for the Google Sheets page and I ran an OS update. Off course I checked the change history of the code but nothing happened. I checked the access rights of the user for the spreadsheet (not for the code, since I cannot find that...)

The user reports that this issue occured earlier, but only now and then...

The error message looks like this: error message

The error log for the respective user:

and the debugger info

From my own account all looks normal: error log from my own account is succesful


Solution

  • Delete unused lines

    While testing your code, I noticed that line 14 is grayed out, indicating that it isn't declared.

    var currentCell = selection.getCurrentCell();
    

    Similarly, when I tried to comment out line 12, it also showed that it's not declared.

    var selection = s.getSelection();
    

    Sample 1


    I encountered an issue with your code initially it didn't work at first. However, after trying it multiple times, it eventually started responding as expected. You can report this in the Issue Tracker, line 14 has a bug that needs to be addressed if you plan to use that code in the future.