Home > Back-end >  Google Sheets script is taking to long, can i use Cache to remedy that?
Google Sheets script is taking to long, can i use Cache to remedy that?

Time:12-19

I have a function that will input data typed in one sheet into another sheet (database) the sheet puts the data entered in the first blank row and the resets the box for the next input

However it takes the script around 11 seconds to run which is a bit to slow i have tried minimizing my api calls but it really dosent do anything so im guessing its because of the size of the database (Currently 25000 Rows and 10 colums

i was thinking of trying to use cache to help me out but dont know if that would do anything for me since im not trying to get data from the database i only need the last row in the database and that will be a new one everytime anyways.

Hope my question is making sense im failry new at this :)

Here is the code im using

function CCBox() 
{
  var myGoogleSheet = SpreadsheetApp.getActiveSpreadsheet();
  var Indtastning = myGoogleSheet.getSheetByName("Indtastning");
  var Database = myGoogleSheet.getSheetByName("Database");
  var ui =SpreadsheetApp.getUi();
  var blankrow=Database.getLastRow() 1;

  if (ui.Button.OK)
  {
    //Henter Data og setter det ind i databasen
    Database.getRange(blankrow, 1).setValue(Indtastning.getRange("A3").getValue());
    Database.getRange(blankrow, 2).setValue(Indtastning.getRange("D3").getValue());
    Database.getRange(blankrow, 3).setValue(Indtastning.getRange("F3").getValue());
    Database.getRange(blankrow, 4).setValue(Indtastning.getRange("H3").getValue());
    Database.getRange(blankrow, 15).setValue(Indtastning.getRange("M3").getValue());

    Database.getRange(blankrow, 5).setValue(Indtastning.getRange("E10").getValue());
    Database.getRange(blankrow, 6).setValue(Indtastning.getRange("G10").getValue());
    Database.getRange(blankrow, 7).setValue(Indtastning.getRange("I10").getValue());
    Database.getRange(blankrow, 8).setValue(Indtastning.getRange("M10").getValue());
    Database.getRange(blankrow, 9).setValue(Indtastning.getRange("K10").getValue());

    Database.getRange(blankrow, 10).setValue(Indtastning.getRange("E18").getValue());
    Database.getRange(blankrow, 11).setValue(Indtastning.getRange("G18").getValue());
    Database.getRange(blankrow, 12).setValue(Indtastning.getRange("I18").getValue());
    Database.getRange(blankrow, 13).setValue(Indtastning.getRange("M18").getValue());
    Database.getRange(blankrow, 14).setValue(Indtastning.getRange("K18").getValue());

    //Rydder Felterne til ny indtastning
    Indtastning.getRange("A3:I5").clearContent();
    Indtastning.getRange("M3:O5").clearContent();
    Indtastning.getRange("E10:O12").clearContent();
    Indtastning.getRange("E18:O20").clearContent();

    myGoogleSheet.toast("Kvittering overført korrekt","           
  • Related