Overview:
I'm attempting to Copy a list of records from one sheet tab to another, in this case the Index tab to the All Work Orders tab. The data set contains 44 columns, and on average approximately 200 - 300 rows. The Goal of the apps script function provided, is to copy the list of rows from the origin (Index) tab, to destination (All Work Orders) tab.
Current issue:
When the function is run/executed, it starts copying the list of records but after a few minutes, I keep receiving the following error message: (exceeded maximum execution time) and the function/copy process stops mid execution. How can I resolve this error?
Further guidance is much appreciated. Thanks
function copyDatabase_25() {
var ui = SpreadsheetApp.getUi();
var response=ui.alert("Complete", "Are you sure?", ui.ButtonSet.YES_NO);
//checking the user response
if(response==ui.Button.NO)
{
return; //exit from this function
}
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName("Index");
var desinationsheet = ss.getSheetByName("All Work Orders");
var startRow = 2;
var numRows = sheet.getLastRow() - startRow + 1;
var startCol = 24;
var numCols = 44;
var startColTarget = 1;
var dataRange = sheet.getRange(startRow, startCol, numRows, numCols);
var data = dataRange.getValues();
var Copy = "Copy";
var firstEmptyRow = sheet.getRange("A2:AQ").getNextDataCell(SpreadsheetApp.Direction.DOWN).getRow() + 1;
var dataToCopy = data.filter(row => row[2] !== Copy);
desinationsheet.getRange(firstEmptyRow, startColTarget, dataToCopy.length, dataToCopy[0].length).setValues(dataToCopy);
ss.toast("Completed successfully")
}