Script Runs Slow and Times Out

23 views
Skip to first unread message

Jolene Slama-Saenz

unread,
Feb 17, 2023, 9:32:24 AM2/17/23
to Google Apps Script Community
We are having some issues with this script running very slowly and timing out.  It doesn't seem like a complex script so I am not sure why.  The only other thing is that google doc has about 8 people live on it at once (but not always inputting stuff) so not sure if that would affect it.  

The script is supposed to timestamp on the row twice and then once it is marked as Complete, move it to another tab.

function archOpsRow(event) {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var s = event.source.getActiveSheet();
  var r = event.source.getActiveRange();

  if(s.getName() == "OPEN" && r.getColumn() == 6 && r.getValue() == "Complete") {
    var row = r.getRow();
    var numColumns = s.getLastColumn();
    var targetSheet = ss.getSheetByName("CLOSED");
    var target = targetSheet.getRange(targetSheet.getLastRow() + 1, 1);
    s.getRange(row, 1, 1, numColumns).moveTo(target);
    s.deleteRow(row);
  }
}

function onEdit(e) {
  var sh = e.source.getActiveSheet();
  var sheets = ['OPEN']; // Which sheets to run the code.

  // Columns with the data to be tracked. 1 = A, 2 = B...
  var ind = [2, 7].indexOf(e.range.columnStart); 

  // Which columns to have the timestamp, related to the data cells.
  // Data in 1 (A) will have the timestamp in 4 (D)
  var stampCols = [1, 8]

  if(sheets.indexOf(sh.getName()) == -1 || ind == -1) return;

  // Insert/Update the timestamp.
  var timestampCell = sh.getRange(e.range.rowStart, stampCols[ind]);
  SpreadsheetApp.flush();
  timestampCell.setValue(typeof e.value == 'object' ? null : new Date()).setNumberFormat("mm/dd hh:mm");
Reply all
Reply to author
Forward
0 new messages