How to Increment Row Position Every Time a Script Runs in Google Sheets

google sheetsgoogle-apps-script

I am currently storing a value each day using the function below:

function addTrigger() {
  ScriptApp.newTrigger("updateCell").timeBased().atHour(13).everyDays(1).create();
}

function updateCell() {
  var url = "https://docs.google.com/spreadsheets/d/12yxNcp0n5_-------------d6B81m6QcjrKXTQDvyx0/edit#gid=377838361";
  var cellOut = "L23";
  var cellIn = "B19";
  var value = SpreadsheetApp.openByUrl(url).getRange(cellIn).getValue();
  SpreadsheetApp.openByUrl(url).getRange(cellOut).setValue(value);
}

I would like to be able to increment the row value each time that the script is run. Since the variable call is done at each run of the script I would assume that there is no global variables to use. So how could one have a variable that increment with each run of the script.

I have read about using PropertiesService to make a sort of global variable, however there must be some more standardized way to increment a value for each time a script is run in google sheets scripts.

I am fully aware that I need to set my Range using Col and Row arguments so I do not need assistance on that, but on how to increment the value that I can put in as the Row.

Truly thankful for your help

Best Answer

In a general sense, in Google Apps Script, the most "standardized way" to have a variable that increments on each execution (a persistent variable) that we could use is the Google Apps Script Properties Service

Another common way is to save the row number is to save it in a spreadsheet cell.